/// <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="sender"> /// The source of the event; typically <see cref="NavigationHelper"/>. /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { App.IsInternetAvailable(); int id = await AdData.GetAdId(); int count = MemoryManager.AppMemoryUsageLimit / (1024 * 1024) > 700 ? 55 : 40; HelperMethods.CreateSingleAdUnit(id, "HorizontalAdSmall", AdGrid); HelperMethods.CreateAdUnits(id, "HorizontalAdSmall", AdGrid2, count); // Setup the underlying UI string champKey = (string)e.NavigationParameter; champions = await StatsDataSource.GetChampionsAsync(); // Could be passed either the key or name, check for either case champInfo = champions.ChampionInfos.Where(x => x.Key == champKey).FirstOrDefault().Value; if (champInfo == null) champInfo = champions.ChampionInfos.Values.Where(x => x.Name == champKey).FirstOrDefault(); this.DefaultViewModel["Champion"] = champInfo; this.DefaultViewModel["Filter"] = champions.ChampionInfos.OrderBy(x => x.Value.Name); // If navigating via a counterpick, on loading that page, remove the previous history so the back page will go to main or role, not champion var prevPage = Frame.BackStack.ElementAt(Frame.BackStackDepth - 1); if (prevPage.SourcePageType.Equals(typeof(ChampionPage))) { Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1); } // Grab the champion feedback from the server await commentViewModel.GetChampionFeedbackAsync(champInfo.Name); // Check if an there was no champion retrieved as well as an error message (must be internet connection problem) if (commentViewModel.ChampionFeedback == null){ MessageDialog messageBox = new MessageDialog("Make sure your internet connection is working and try again!"); await messageBox.ShowAsync(); Application.Current.Exit(); } // Collapse the progress ring once counters have been loaded assuming the textboxes load first DefaultViewModel["LoadingVisibility"] = Visibility.Collapsed; // Make updates to champion comments observable this.DefaultViewModel["ChampionFeedback"] = commentViewModel.ChampionFeedback; }