protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is not ComicNavigationItemPageNavigationArguments args) { throw new ProgrammerError("A ComicRootPage must receive a ComicNavigationItemPageNavigationArguments as its parameter."); } this._navigationTag = args.NavigationTag; this._comicItem = args.ComicItem; var savedState = e.NavigationMode switch { NavigationMode.New => null, NavigationMode.Back => ComicItemGridCache.PopStack(this.NavigationTag, this.ComicItem.Title), _ => throw new ProgrammerError("Unexpected switch case"), }; this.viewModel = ComicItemGridViewModel.ForSecondLevelNavigationTag(this, args.MainViewModel, args.ComicItem.Comics, args.Properties, savedState); this.ComicsCount = viewModel.TotalItemCount; this.Initialized?.Invoke(this); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => this.InnerContentFrame.Navigate(typeof(ComicItemGrid), new ComicItemGridNavigationArguments { ViewModel = viewModel, HighlightedComicItem = args.ComicItem, OnNavigatedTo = (grid, e) => { this.ComicItemGrid = grid; grid.FinishNavigateInConnectedAnimationIfExists(this.ComicItem); } }) ); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is not ComicWorkItemPageNavigationArguments args) { throw new ProgrammerError("A ComicWorkItemPage must receive a ComicWorkItemPageNavigationArguments as its parameter."); } this._viewModel = args.ViewModel; await this.ViewModel.InitializeAsync(); if (this.ViewModel.Initialized) { this.useThumbnails = this.ViewModel.ShouldUseThumbnails(); } // After we change the visual state here, if the grid had already loaded, it may have initialized // with a wrong value for useThumbnails. So we call it again. // Note: Calling VisualStateManager.GoToState will set this.ComicSubitemGrid.ItemsPanelRoot to null (temporarily). // For that purpose we must do this before setting visual state. if (this.ComicSubitemGrid.IsLoaded) { this.RecalculateGridItemSize(this.ComicSubitemGrid); } if (this.ViewModel.Subitems.Count == 0) { _ = VisualStateManager.GoToState(this, "NoSubitems", false); } else { if (this.useThumbnails) { _ = VisualStateManager.GoToState(this, "ThumbnailsVisible", false); } else { _ = VisualStateManager.GoToState(this, "ThumbnailsHidden", false); } } switch (e.NavigationMode) { case NavigationMode.New: // Note: We may change the HighlightedComicItem's thumbnail size by setting visual manager state, // so we should start the connected animation after. this.HighlightedComicItem.TryStartConnectedAnimationToThumbnail(this.ViewModel.ComicItem); break; case NavigationMode.Back: _ = ComicItemGridCache.PopStack(this.NavigationTag, this.PageName); break; default: throw new ProgrammerError("Unexpected navigation mode"); } this.ViewModel.ComicItem.PropertyChanged += this.ComicItem_PropertyChanged; this.SynchronizeLovedStatusToUI(); if (await this.ViewModel.TryLoadDescriptionsAsync(this.InfoTextBlock)) { this.ToggleInfoPaneButton.Visibility = Visibility.Visible; } if (this.ViewModel.Initialized && this.useThumbnails) { await this.ViewModel.LoadThumbnailsAsync(); } }