Don't like ads? PRO users don't see any ads ;-)
Guest

MainPage.xaml.cs

By: meredithleu on May 25th, 2012  |  syntax: C#  |  size: 1.84 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using Microsoft.Phone.Shell;
  14. using System.Collections.ObjectModel;
  15.  
  16. namespace MentalStack
  17. {
  18.     public partial class MainPage : PhoneApplicationPage
  19.     {
  20.         private ObservableCollection<Note> thoughts;
  21.         public ObservableCollection<Note> Thoughts{
  22.         get
  23.         {
  24.             if (thoughts == null)
  25.             {
  26.                 thoughts = new ObservableCollection<Note>();
  27.             }
  28.             return thoughts;
  29.         }
  30.     }
  31.         // Constructor
  32.         public MainPage()
  33.         {
  34.             InitializeComponent();
  35.             Note item = new Note("hi", "just testing");
  36.             thoughts = new ObservableCollection<Note>();
  37.             thoughts.Add(new Note("aaa", "BBB"));
  38.         }
  39.  
  40.         protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  41.         {
  42.             base.OnNavigatedTo(e);
  43.             if (PhoneApplicationService.Current.State.ContainsKey("Thoughts"))
  44.             {
  45.                 thoughts = (ObservableCollection<Note>)PhoneApplicationService.Current.State["Thoughts"];
  46.             }
  47.         }
  48.  
  49.         protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
  50.         {
  51.             PhoneApplicationService.Current.State["Thoughts"] = thoughts;
  52.             base.OnNavigatedFrom(e);
  53.         }
  54.  
  55.         private void addThought(object sender, EventArgs e)
  56.         {
  57.             NavigationService.Navigate(new Uri("/PageAddThought.xaml", UriKind.Relative));          
  58.         }
  59.     }
  60. }