protected override void OnNavigatedFrom(NavigationEventArgs e) { if (((App)App.Current).IsSuspending) { // Save volatile state in case we get terminated later on // then we can restore as if we'd never been gone ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue(); ITextRange range = detials.Document.GetRange(0, TextConstants.MaxUnitCount); composite["title"] = title.Text; composite["detials"] = range.Text; composite["date"] = date.Date; ApplicationData.Current.LocalSettings.Values["TheWorkInProgress"] = composite; if (ViewModles.SelectItem != null) { ApplicationData.Current.LocalSettings.Values["selectitem"] = ViewModles.AllItems.IndexOf(ViewModles.SelectItem); } List <string> L = new List <string>(); var allitems = ViewModles.AllItems; foreach (var a in allitems) { var item = new myItem(a.id, a.title, a.detail, a.date, a.completed); L.Add(JsonConvert.SerializeObject(item)); } ApplicationData.Current.LocalSettings.Values["allitems"] = JsonConvert.SerializeObject(L); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; if (e.NavigationMode == NavigationMode.New) { if (ViewModles.SelectItem != null) { CreateButton.Content = "Update"; a.Text = ViewModles.SelectItem.title; ITextRange range = b.Document.GetRange(0, TextConstants.MaxUnitCount); range.Text = ViewModles.SelectItem.detail; date1.Date = ViewModles.SelectItem.date; } else { CreateButton.Content = "Create"; } ApplicationData.Current.LocalSettings.Values.Remove("Item"); ApplicationData.Current.LocalSettings.Values.Remove("allitems"); ApplicationData.Current.LocalSettings.Values.Remove("selectitem"); Debug.WriteLine("00000"); } else { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("allitems")) { ViewModles.AllItems.Clear(); List <string> L = JsonConvert.DeserializeObject <List <string> >( (string)ApplicationData.Current.LocalSettings.Values["allitems"]); foreach (var l in L) { myItem a = JsonConvert.DeserializeObject <myItem>(l); MyList item = new MyList(a.id, a.title, a.detail, a.date.Date, a.finish); item.completed = a.finish; ViewModles.AllItems.Add(item); } } if (ApplicationData.Current.LocalSettings.Values.ContainsKey("selectitem")) { ViewModles.SelectItem = ViewModles.AllItems[(int)(ApplicationData.Current.LocalSettings.Values["selectitem"])]; } if (ApplicationData.Current.LocalSettings.Values.ContainsKey("TheWorkInProgress")) { var composite = ApplicationData.Current.LocalSettings.Values["TheWorkInProgress"] as ApplicationDataCompositeValue; a.Text = (string)composite["title"]; ITextRange range = b.Document.GetRange(0, TextConstants.MaxUnitCount); range.Text = (string)composite["detials"]; date1.Date = (DateTimeOffset)composite["date"]; ApplicationData.Current.LocalSettings.Values.Remove("TheWorkInProgress"); } } }