Skip to content

Commit

Permalink
handle esc key in setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 29, 2023
1 parent 212b96c commit c7017fc
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Starward/Pages/Setting/SettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,43 @@ public SettingPage()
}


protected override void OnLoaded()
{
MainWindow.Current.KeyDown += SettingPage_KeyDown;
}


protected override void OnUnloaded()
{
MainWindow.Current.KeyDown -= SettingPage_KeyDown;
WeakReferenceMessenger.Default.UnregisterAll(this);
}


private void SettingPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e)
{
try
{
if (e.Handled)
{
return;
}
if (e.VirtualKey == Windows.System.VirtualKey.Escape)
{
ClosePage();
e.Handled = true;
}
}
catch { }
}


private void ClosePage()
{
MainWindow.Current.CloseOverlayPage();
}


private LanguageChangedMessage? _languageChangedMessage;


Expand Down Expand Up @@ -59,7 +90,7 @@ private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewIte
_languageChangedMessage.Completed = true;
WeakReferenceMessenger.Default.Send(_languageChangedMessage);
}
MainWindow.Current.CloseOverlayPage();
ClosePage();
return;
}
var type = item.Tag switch
Expand Down

0 comments on commit c7017fc

Please sign in to comment.