/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { navParam = navigationParameter as postDate; pageTitle.Text = "Posts for " + navParam.month_name + " " + navParam.year; ViewCommentsButton.Visibility = Visibility.Collapsed; progressRing.Visibility = Visibility.Visible; Windows.UI.Xaml.Media.Animation.Storyboard sb = this.FindName("PopInStoryBoard") as Windows.UI.Xaml.Media.Animation.Storyboard; if (sb != null) sb.Begin(); // TODO: Assign a bindable group to this.DefaultViewModel["Group"] // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"] FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"]; if (feedDataSource != null) { await feedDataSource.GetFeedsAsync("date", navParam.year + navParam.month); } RootObject feedData = FeedDataSource.GetFeed(); if (feedData != null) { this.DefaultViewModel["Feed"] = feedData; this.DefaultViewModel["Items"] = feedData.posts; if (feedData.posts.Count == 0) itemTitle.Text = "There are no posts yet."; } if (pageState == null) { // When this is a new page, select the first item automatically unless logical page // navigation is being used (see the logical page navigation #region below.) if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null) { this.itemsViewSource.View.MoveCurrentToFirst(); } else { //this.itemsViewSource.View.MoveCurrentToPosition(-1); } } else { // Restore the previously saved state associated with this page if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null) { // TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected // item as specified by the value of pageState["SelectedItem"] string itemTitle = (string)pageState["SelectedItem"]; Post selectedItem = FeedDataSource.GetItem(itemTitle); this.itemsViewSource.View.MoveCurrentTo(selectedItem); } } if (feedData.posts.Count == 0) ViewCommentsButton.Visibility = Visibility.Collapsed; else ViewCommentsButton.Visibility = Visibility.Visible; progressRing.Visibility = Visibility.Collapsed; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { navParam = navigationParameter as postDate; pageTitle.Text = "Posts for " + navParam.month_name + " " + navParam.year; ViewCommentsButton.Visibility = Visibility.Collapsed; progressRing.Visibility = Visibility.Visible; Windows.UI.Xaml.Media.Animation.Storyboard sb = this.FindName("PopInStoryBoard") as Windows.UI.Xaml.Media.Animation.Storyboard; if (sb != null) { sb.Begin(); } // TODO: Assign a bindable group to this.DefaultViewModel["Group"] // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"] FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"]; if (feedDataSource != null) { await feedDataSource.GetFeedsAsync("date", navParam.year + navParam.month); } RootObject feedData = FeedDataSource.GetFeed(); if (feedData != null) { this.DefaultViewModel["Feed"] = feedData; this.DefaultViewModel["Items"] = feedData.posts; if (feedData.posts.Count == 0) { itemTitle.Text = "There are no posts yet."; } } if (pageState == null) { // When this is a new page, select the first item automatically unless logical page // navigation is being used (see the logical page navigation #region below.) if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null) { this.itemsViewSource.View.MoveCurrentToFirst(); } else { //this.itemsViewSource.View.MoveCurrentToPosition(-1); } } else { // Restore the previously saved state associated with this page if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null) { // TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected // item as specified by the value of pageState["SelectedItem"] string itemTitle = (string)pageState["SelectedItem"]; Post selectedItem = FeedDataSource.GetItem(itemTitle); this.itemsViewSource.View.MoveCurrentTo(selectedItem); } } if (feedData.posts.Count == 0) { ViewCommentsButton.Visibility = Visibility.Collapsed; } else { ViewCommentsButton.Visibility = Visibility.Visible; } progressRing.Visibility = Visibility.Collapsed; }