1
0
mirror of https://github.com/chylex/Backup-Essentials.git synced 2025-08-10 06:40:41 +02:00

Added a page switch handler

This commit is contained in:
chylex 2015-04-13 17:28:11 +02:00
parent ac17dbe561
commit 25b4fcf670
2 changed files with 18 additions and 2 deletions

View File

@ -27,13 +27,18 @@ namespace BackupEssentials{
InitializeComponent();
Instance = this;
Loaded += (args, sender) => {
Loaded += (sender, args) => {
Dispatcher.BeginInvoke(DispatcherPriority.Loaded,new Action(() => {
DataStorage.Load();
}));
};
Closed += (args, sender) => {
Closing += (sender, args) => {
IPageSwitchHandler switchHandler = ContentFrame.Content as IPageSwitchHandler;
if (switchHandler != null && switchHandler.OnSwitch())args.Cancel = true;
};
Closed += (sender, args) => {
DataStorage.Save(true);
ExplorerIntegration.Refresh(true);
};
@ -126,6 +131,9 @@ namespace BackupEssentials{
}
public void ShowPage(Type pageType, object data){
IPageSwitchHandler switchHandler = ContentFrame.Content as IPageSwitchHandler;
if (switchHandler != null && switchHandler.OnSwitch())return;
Page page = null;
ContentFrame.Navigate(pageType == null ? null : page = AppPageManager.GetPage(pageType));
if (ContentFrame.NavigationService.CanGoBack)ContentFrame.NavigationService.RemoveBackEntry();

View File

@ -0,0 +1,8 @@
namespace BackupEssentials.Pages{
interface IPageSwitchHandler{
/// <summary>
/// Called when the display page is about to change, or when the window is closing. Return true to stop the switch (or closing) from happening.
/// </summary>
bool OnSwitch();
}
}