Windows phone 7 WP7停止页面导航/返回
当用户点击后退按钮后单击“取消”按钮时,如何阻止应用程序返回Windows phone 7 WP7停止页面导航/返回,windows-phone-7,Windows Phone 7,当用户点击后退按钮后单击“取消”按钮时,如何阻止应用程序返回 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { var buttonInfo = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.OKCancel); if (butt
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
var buttonInfo = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.OKCancel);
if (buttonInfo == MessageBoxResult.OK)
{
this.NavigationService.GoBack();
}
else
{
//How to stop page from navigating
}
}
使用
CancelEventArgs
取消操作、属性
再多一点
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (e.Cancel)
return;
var buttonInfo = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.OKCancel);
if (buttonInfo == MessageBoxResult.OK)
{
**//this line may useful if you are in the very first page of your app**
if (this.NavigationService.CanGoBack)
{
this.NavigationService.GoBack();
}
}
else
{
//Stop page from navigating
e.Cancel = true;
}
}
完美的非常感谢你!很高兴它对你有用。您还应该检查偶数是否已经取消,在这种情况下什么也不做。在这样做时要小心,因为根据使用情况,偶数可能会违反认证要求;明确地
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (e.Cancel)
return;
var buttonInfo = MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButton.OKCancel);
if (buttonInfo == MessageBoxResult.OK)
{
**//this line may useful if you are in the very first page of your app**
if (this.NavigationService.CanGoBack)
{
this.NavigationService.GoBack();
}
}
else
{
//Stop page from navigating
e.Cancel = true;
}
}