Windows Phone - 从 mainpaga.xaml 取消
Windows Phone - cancel back from mainpaga.xaml
我想覆盖主页上的后退按钮。在其他页面上有效的内容在主页面上无效。这是我的代码:
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
if (MessageBox.Show("Wszystkie zmiany zostaną odrzucone", "Odrzucenie Zmian", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
问题是它显示了确认退出的消息框,但是它也在退出应用程序,所以无论如何确认或取消都没有意义。
您必须覆盖 OnBackKeyPress 而不是 OnNavigatingFrom
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (MessageBox.Show("Wszystkie zmiany zostaną odrzucone", "Odrzucenie Zmian", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
我想覆盖主页上的后退按钮。在其他页面上有效的内容在主页面上无效。这是我的代码:
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
if (MessageBox.Show("Wszystkie zmiany zostaną odrzucone", "Odrzucenie Zmian", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
问题是它显示了确认退出的消息框,但是它也在退出应用程序,所以无论如何确认或取消都没有意义。
您必须覆盖 OnBackKeyPress 而不是 OnNavigatingFrom
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (MessageBox.Show("Wszystkie zmiany zostaną odrzucone", "Odrzucenie Zmian", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Cancel = true;
}
}