如何自定义BackPressed事件,以便BackPressed返回指定的“主页”时的每个页面。不需要维护堆栈。
public App()
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
this.InitializeComponent();
this.Suspending += this.OnSuspending;
}
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null)
{
return;
}
if (frame.CanGoBack && !e.Handled)
{
e.Handled = true;
frame.GoBack();
}
}
答案 0 :(得分:0)
您需要覆盖后退方法,并且需要对其进行保护。