我正在创建一个Windows通用应用程序,我想为(硬件)后退按钮实现一些行为。我可以使用Windows Phone '使用Windows.Phone.UI.Input;' 和 'HardwareButtons.BackPressed + = HardwareButtons_BackPressed;'
但似乎无法使用通用应用程序,这种行为将发生在共享的页面上。我怎么能这样做?
答案 0 :(得分:1)
您可以使用SystemNavigationManager
SystemNavigationManager currentView = SystemNavigationManager.GetForCurrentView();
并有一个像这样的事件处理程序:
currentView.BackRequested += CurrentView_BackRequested;
private void CurrentView_BackRequested(object sender,BackRequestedEventArgs e) {
e.Handled = true;
if(Frame.CanGoBack)
try { Frame.GoBack(); }
catch(Exception) { }
}
在你应用的角落(桌面模式)的可见后退按钮:
currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;