コード例 #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                AppViewBackButtonVisibility.Visible;

            if (e.NavigationMode == NavigationMode.New)
            {
                if (ViewModel.SelectedItem != null)
                {
                    create_update.Content = "Update";
                    title.Text            = ViewModel.SelectedItem.title;
                    ITextRange range = detail.Document.GetRange(0, TextConstants.MaxUnitCount);
                    range.Text = ViewModel.SelectedItem.detail;
                    ddl.Date   = ViewModel.SelectedItem.date;
                    pic.Source = ViewModel.SelectedItem.img;
                }
                // If this is a new navigation, this is a fresh launch so we can discard any saved state
                ApplicationData.Current.LocalSettings.Values.Remove("Item");
                ApplicationData.Current.LocalSettings.Values.Remove("allitems");
                ApplicationData.Current.LocalSettings.Values.Remove("selectitem");
            }
            else
            {
                // Try to restore state if any, in case we were terminated
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("allitems"))
                {
                    var allitems = ViewModel.getItems;
                    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);
                        TodoItem item = new TodoItem(a.date.Date, a.imgname, a.title, a.detail, a.finish);
                        allitems.Add(item);
                    }
                }
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("selectitem"))
                {
                    ViewModel.SelectedItem = ViewModel.getItems[(int)(ApplicationData.Current.LocalSettings.Values["selectitem"])];
                }
                if (ApplicationData.Current.LocalSettings.Containers.ContainsKey("Item"))
                {
                    ApplicationDataContainer Item = ApplicationData.Current.LocalSettings.Containers["Item"];
                    create_update.Content = Item.Values["btn"] as string;
                    title.Text            = Item.Values["title"] as string;
                    ITextRange range = detail.Document.GetRange(0, TextConstants.MaxUnitCount);
                    range.Text        = Item.Values["detail"] as string;
                    ddl.Date          = (DateTimeOffset)(Item.Values["date"]);
                    Common.selectName = Item.Values["imgname"] as string;

                    if (Common.selectName == "")
                    {
                        pic.Source = new BitmapImage(new Uri("ms-appx:///Assets/todo.png"));
                    }
                    else
                    {
                        var file = await ApplicationData.Current.LocalFolder.GetFileAsync(Common.selectName);

                        IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                        BitmapImage bitmapImage = new BitmapImage();
                        await bitmapImage.SetSourceAsync(fileStream);

                        pic.Source = bitmapImage;
                    }
                }
            }
        }
コード例 #2
0
ファイル: TodoItemViewModel.cs プロジェクト: Emma11111/UWP
 public void RemoveItem()
 {
     items.Remove(selectedItem);
     SelectedItem = null;
 }