Skip to content

Commit

Permalink
Finally I can goback!
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Dec 22, 2024
1 parent 9b96f2b commit e85d56f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 80 deletions.
64 changes: 0 additions & 64 deletions source/iNKORE.UI.WPF.Modern.Gallery/Helpers/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,68 +99,4 @@ private void UpdateBackButton()
this.CurrentNavView.IsBackEnabled = this.Frame.CanGoBack ? true : false;
}
}

/// <summary>
/// Represents the method that will handle the <see cref="NavigationHelper.LoadState"/>event
/// </summary>
public delegate void LoadStateEventHandler(object sender, LoadStateEventArgs e);
/// <summary>
/// Represents the method that will handle the <see cref="NavigationHelper.SaveState"/>event
/// </summary>
public delegate void SaveStateEventHandler(object sender, SaveStateEventArgs e);

/// <summary>
/// Class used to hold the event data required when a page attempts to load state.
/// </summary>
public class LoadStateEventArgs : EventArgs
{
/// <summary>
/// The parameter value passed to <see cref="Frame.Navigate(Type, object)"/>
/// when this page was initially requested.
/// </summary>
public object NavigationParameter { get; private set; }
/// <summary>
/// A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.
/// </summary>
public Dictionary<string, object> PageState { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="LoadStateEventArgs"/> class.
/// </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>
public LoadStateEventArgs(object navigationParameter, Dictionary<string, object> pageState)
: base()
{
this.NavigationParameter = navigationParameter;
this.PageState = pageState;
}
}
/// <summary>
/// Class used to hold the event data required when a page attempts to save state.
/// </summary>
public class SaveStateEventArgs : EventArgs
{
/// <summary>
/// An empty dictionary to be populated with serializable state.
/// </summary>
public Dictionary<string, object> PageState { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="SaveStateEventArgs"/> class.
/// </summary>
/// <param name="pageState">An empty dictionary to be populated with serializable state.</param>
public SaveStateEventArgs(Dictionary<string, object> pageState)
: base()
{
this.PageState = pageState;
}
}
}
13 changes: 9 additions & 4 deletions source/iNKORE.UI.WPF.Modern.Gallery/ItemPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/iNKORE.UI.WPF.Modern.Gallery/ItemsPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions source/iNKORE.UI.WPF.Modern.Gallery/SearchResultsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ public IEnumerable<Filter> 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)
Expand Down
10 changes: 8 additions & 2 deletions source/iNKORE.UI.WPF.Modern.Gallery/SectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ namespace iNKORE.UI.WPF.Modern.Gallery
/// </summary>
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)
Expand Down
2 changes: 1 addition & 1 deletion source/iNKORE.UI.WPF.Modern.Gallery/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
}
}
10 changes: 9 additions & 1 deletion source/iNKORE.UI.WPF.Modern/Controls/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

/// <summary>
/// Represents content that a Frame control can navigate to.
/// </summary>
public class Page : PageFunctionBase
public class Page : System.Windows.Controls.Page
{
static Page()
{
Expand Down Expand Up @@ -66,6 +71,7 @@ private void UpdateFrame(NavigationService navigationService)

/// <summary>
/// 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.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
Expand All @@ -79,6 +85,7 @@ protected virtual void OnNavigatedTo(NavigationEventArgs e)
/// <summary>
/// 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.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
Expand All @@ -92,6 +99,7 @@ protected virtual void OnNavigatingFrom(NavigatingCancelEventArgs e)
/// <summary>
/// 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.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
Expand Down

0 comments on commit e85d56f

Please sign in to comment.