Example #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is not ComicRootPageNavigationArguments args)
            {
                throw new ProgrammerError("A ComicRootPage must receive a ComicRootPageNavigationArguments as its parameter.");
            }

            this._navigationTag = args.NavigationTag;

            var savedState = ComicItemGridCache.GetRoot(args.NavigationTag);

            // We only want to restore the scrollviewer position if the user navigates *back* to this page.
            if (savedState is not null && e.NavigationMode is NavigationMode.New)
            {
                savedState.ScrollOffset = 0;
            }

            this.viewModel   = ComicItemGridViewModel.ForTopLevelNavigationTag(this, args.MainViewModel, 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,
                OnNavigatedTo = (grid, _) => this.ComicItemGrid = grid
            }));
        }
        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 void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            // For now, we push useless information onto the cache to keep everything else working
            if (e.NavigationMode is NavigationMode.New)
            {
                ComicItemGridCache.PushStack(this.NavigationTag, this.PageName, new ComicItemGridState(new(), 0, this.MainViewModel.LastModified));
            }

            // Ideally this should be automated
            this.ViewModel.RemoveEventHandlers();
        }
Example #4
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            if (this.ComicItemGrid is null)
            {
                throw new ProgrammerError("Navigating out of a ComicNavigationItemPage that wasn't initialized.");
            }

            ComicItemGridCache.PutRoot(this.NavigationTag, this.ComicItemGrid.GetSaveState());

            // Ideally this should be automated
            this.viewModel !.RemoveEventHandlers();
            this.ComicItemGrid.DisposeAndInvalidate();
        }
        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();
            }
        }