From e85d56f038c46468ba46ca259d864a9862dc7559 Mon Sep 17 00:00:00 2001 From: Yoojun Zhou Date: Sun, 22 Dec 2024 15:33:31 +0800 Subject: [PATCH] Finally I can goback! --- .../Helpers/NavigationHelper.cs | 64 ------------------- .../ItemPage.xaml.cs | 13 ++-- .../ItemsPageBase.cs | 2 +- .../Navigation/NavigationRootPage.xaml.cs | 8 +-- .../Windows/HyperlinkButtonPage.xaml.cs | 2 +- .../SearchResultsPage.xaml.cs | 10 ++- .../SectionPage.xaml.cs | 10 ++- .../SettingsPage.xaml.cs | 2 +- source/iNKORE.UI.WPF.Modern/Controls/Page.cs | 10 ++- 9 files changed, 41 insertions(+), 80 deletions(-) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Helpers/NavigationHelper.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Helpers/NavigationHelper.cs index be77ec92..dea6d234 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Helpers/NavigationHelper.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Helpers/NavigationHelper.cs @@ -99,68 +99,4 @@ private void UpdateBackButton() this.CurrentNavView.IsBackEnabled = this.Frame.CanGoBack ? true : false; } } - - /// - /// Represents the method that will handle the event - /// - public delegate void LoadStateEventHandler(object sender, LoadStateEventArgs e); - /// - /// Represents the method that will handle the event - /// - public delegate void SaveStateEventHandler(object sender, SaveStateEventArgs e); - - /// - /// Class used to hold the event data required when a page attempts to load state. - /// - public class LoadStateEventArgs : EventArgs - { - /// - /// The parameter value passed to - /// when this page was initially requested. - /// - public object NavigationParameter { get; private set; } - /// - /// A dictionary of state preserved by this page during an earlier - /// session. This will be null the first time a page is visited. - /// - public Dictionary PageState { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The parameter value passed to - /// when this page was initially requested. - /// - /// - /// A dictionary of state preserved by this page during an earlier - /// session. This will be null the first time a page is visited. - /// - public LoadStateEventArgs(object navigationParameter, Dictionary pageState) - : base() - { - this.NavigationParameter = navigationParameter; - this.PageState = pageState; - } - } - /// - /// Class used to hold the event data required when a page attempts to save state. - /// - public class SaveStateEventArgs : EventArgs - { - /// - /// An empty dictionary to be populated with serializable state. - /// - public Dictionary PageState { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// An empty dictionary to be populated with serializable state. - public SaveStateEventArgs(Dictionary pageState) - : base() - { - this.PageState = pageState; - } - } } diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs index 69f0ecba..b76dba62 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs @@ -41,14 +41,19 @@ public ControlInfoDataItem Item set { _item = value; } } - public ItemPage(ControlInfoDataItem item = null) + public ItemPage() { InitializeComponent(); - + if (System.Windows.MessageBox.Show("Instance of ItemPage created", "", MessageBoxButton.YesNo) == MessageBoxResult.No) throw new Exception("Instance of ItemPage created"); Loaded += (s, e) => SetInitialVisuals(); this.Unloaded += this.ItemPage_Unloaded; + } - if (item != null) LoadData(item); + public static ItemPage Create(ControlInfoDataItem item) + { + var page = new ItemPage(); + if (item != null) page.LoadData(item); + return page; } private void ItemPage_Unloaded(object sender, RoutedEventArgs e) @@ -120,7 +125,7 @@ private void OnRelatedControlClick(object sender, RoutedEventArgs e) var page = new ItemPage(); page.LoadData(b.DataContext as ControlInfoDataItem); - this.Frame.Navigate(new ItemPage(b.DataContext as ControlInfoDataItem)); + this.Frame.Navigate(ItemPage.Create(b.DataContext as ControlInfoDataItem)); } public async void LoadData(ControlInfoDataItem item) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/ItemsPageBase.cs b/source/iNKORE.UI.WPF.Modern.Gallery/ItemsPageBase.cs index a7ba3c5a..84fe0f53 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/ItemsPageBase.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/ItemsPageBase.cs @@ -50,7 +50,7 @@ protected void OnItemGridViewItemClick(object sender, ItemClickEventArgs e) var gridView = (GridView)sender; var item = (ControlInfoDataItem)e.ClickedItem; - this.Frame.Navigate(new ItemPage(item), new DrillInNavigationTransitionInfo()); + this.Frame.Navigate(ItemPage.Create(item), new DrillInNavigationTransitionInfo()); } protected void OnItemGridViewKeyDown(object sender, KeyEventArgs e) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs index b49abdd1..96170b47 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Navigation/NavigationRootPage.xaml.cs @@ -304,12 +304,12 @@ private void OnNavigationViewSelectionChanged(NavigationView sender, NavigationV if (selectedItem.DataContext is ControlInfoDataGroup) { var item = (ControlInfoDataGroup)selectedItem.DataContext; - rootFrame.Navigate(new SectionPage(item)); + rootFrame.Navigate(SectionPage.Create(item)); } else if (selectedItem.DataContext is ControlInfoDataItem) { var item = (ControlInfoDataItem)selectedItem.DataContext; - rootFrame.Navigate(new ItemPage(item)); + rootFrame.Navigate(ItemPage.Create(item)); } } } @@ -381,11 +381,11 @@ private void OnControlsSearchBoxQuerySubmitted(AutoSuggestBox sender, AutoSugges var infoDataItem = args.ChosenSuggestion as ControlInfoDataItem; var itemId = infoDataItem.UniqueId; EnsureItemIsVisibleInNavigation(infoDataItem.Title); - rootFrame.Navigate(new ItemPage(infoDataItem)); + rootFrame.Navigate(ItemPage.Create(infoDataItem)); } else if (!string.IsNullOrEmpty(args.QueryText)) { - RootFrame.Navigate(new SearchResultsPage(args.QueryText)); + RootFrame.Navigate(SearchResultsPage.Create(args.QueryText)); } } diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/HyperlinkButtonPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/HyperlinkButtonPage.xaml.cs index b558d9e8..c508013a 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/HyperlinkButtonPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/HyperlinkButtonPage.xaml.cs @@ -17,7 +17,7 @@ public HyperlinkButtonPage() private async void GoToHyperlinkButton_Click(object sender, RoutedEventArgs e) { - NavigationRootPage.RootFrame.Navigate(new ItemPage(await ControlInfoDataSource.Instance.GetItemAsync(await ControlInfoDataSource.Instance.GetRealmAsync("Windows"), "ToggleButton"))); + NavigationRootPage.RootFrame.Navigate(ItemPage.Create(await ControlInfoDataSource.Instance.GetItemAsync(await ControlInfoDataSource.Instance.GetRealmAsync("Windows"), "ToggleButton"))); } private void Page_Loaded(object sender, RoutedEventArgs e) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs index 9bc4dcca..0ef6c51a 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs @@ -36,10 +36,16 @@ public IEnumerable Filters set { this.SetProperty(ref _filters, value); } } - public SearchResultsPage(string queryText = null) + public SearchResultsPage() { this.InitializeComponent(); - if (queryText != null) LoadData(queryText); + } + + public static SearchResultsPage Create(string queryText) + { + var page = new SearchResultsPage(); + if (queryText != null) page.LoadData(queryText); + return page; } public void LoadData(string queryText) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SectionPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SectionPage.xaml.cs index 451af081..82bea16c 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SectionPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SectionPage.xaml.cs @@ -22,10 +22,16 @@ namespace iNKORE.UI.WPF.Modern.Gallery /// public partial class SectionPage : ItemsPageBase { - public SectionPage(ControlInfoDataGroup group = null) + public SectionPage() { InitializeComponent(); - if (group != null) LoadData(group); + } + + public static SectionPage Create(ControlInfoDataGroup group) + { + var page = new SectionPage(); + if (group != null) page.LoadData(group); + return page; } public void LoadData(ControlInfoDataGroup group) diff --git a/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs b/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs index 89fd7b9f..a58058eb 100644 --- a/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs +++ b/source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs @@ -177,7 +177,7 @@ private void OnResetTeachingTipsButtonClick(object sender, RoutedEventArgs e) private async void soundPageHyperlink_Click(object sender, RoutedEventArgs args) { - this.Frame.Navigate(new ItemPage(await ControlInfoDataSource.Instance.GetItemAsync(await ControlInfoDataSource.Instance.GetRealmAsync("Windows"), "Sound"))); + this.Frame.Navigate(ItemPage.Create(await ControlInfoDataSource.Instance.GetItemAsync(await ControlInfoDataSource.Instance.GetRealmAsync("Windows"), "Sound"))); } } } diff --git a/source/iNKORE.UI.WPF.Modern/Controls/Page.cs b/source/iNKORE.UI.WPF.Modern/Controls/Page.cs index d6e2073f..7b0e9203 100644 --- a/source/iNKORE.UI.WPF.Modern/Controls/Page.cs +++ b/source/iNKORE.UI.WPF.Modern/Controls/Page.cs @@ -5,10 +5,15 @@ namespace iNKORE.UI.WPF.Modern.Controls { + // Something to say here: + // This page used to inherit from PageFunctionBase, but it caused a lot of weird issues. + // So I changed it to inherit from System.Windows.Controls.Page. + // I'm not sure if this is the right way to do it, but it works for now. + /// /// Represents content that a Frame control can navigate to. /// - public class Page : PageFunctionBase + public class Page : System.Windows.Controls.Page { static Page() { @@ -66,6 +71,7 @@ private void UpdateFrame(NavigationService navigationService) /// /// Invoked when the Page is loaded and becomes the current source of a parent Frame. + /// This will be fired only using ui:Frame instead of the original Frame. /// /// /// Event data that can be examined by overriding code. The event data is representative @@ -79,6 +85,7 @@ protected virtual void OnNavigatedTo(NavigationEventArgs e) /// /// Invoked immediately before the Page is unloaded and is no longer the current /// source of a parent Frame. + /// This will be fired only using ui:Frame instead of the original Frame. /// /// /// Event data that can be examined by overriding code. The event data is representative @@ -92,6 +99,7 @@ protected virtual void OnNavigatingFrom(NavigatingCancelEventArgs e) /// /// Invoked immediately after the Page is unloaded and is no longer the current source /// of a parent Frame. + /// This will be fired only using ui:Frame instead of the original Frame. /// /// /// Event data that can be examined by overriding code. The event data is representative