Skip to content

Commit

Permalink
create page base
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 29, 2023
1 parent d124251 commit 554b743
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/Starward/Pages/PageBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Starward.Core;
using Starward.Messages;

namespace Starward.Pages;

public abstract class PageBase : Page
{


public GameBiz CurrentGameBiz { get; private set; }


public PageBase()
{
Loaded += PageEx_Loaded;
Unloaded += PageEx_Unloaded;
WeakReferenceMessenger.Default.Register<LanguageChangedMessage>(this, (_, _) => OnLanguageChanged());
}



private void PageEx_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
OnLoaded();
}


private void PageEx_Unloaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
Loaded -= PageEx_Loaded;
Unloaded -= PageEx_Unloaded;
WeakReferenceMessenger.Default.UnregisterAll(this);
OnUnloaded();
}



protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is GameBiz biz)
{
CurrentGameBiz = biz;
}
}



protected virtual void OnLoaded()
{

}



protected virtual void OnUnloaded()
{

}



protected virtual void OnLanguageChanged()
{

}


}


0 comments on commit 554b743

Please sign in to comment.