-1

我有一个运行异步操作的页面。如何防止用户按下GoBack硬件按钮后返回?

当用户按下手机上的H/W返回按钮时,我希望应用程序被询问用户他是否“真的”想要退出该页面?如果答案是YES而不是GoBack,但答案不是NO,而是停留在同一页面上。

我该怎么做?

MessageBoxResult result = MessageBox.Show("Do you really want to leave this page?", "", MessageBoxButton.OKCancel); 

    if (result == MessageBoxResult.OK) 
     { 
     // .... Go Back 
     } 
    else 
     { 
     // .... Stay on the same page 
     } 

Thx!

回答

3

重写backkeypress事件

protected override void OnBackKeyPress(CancelEventArgs e) 
{ 
    if(MessageBox.Show("Are you sure you want to exit?","Exit?", 
          MessageBoxButton.OKCancel) != MessageBoxResult.OK) 
    { 
     e.Cancel = true; 

    } 
} 
+0

THX,解决了我的问题。 – 2014-10-12 16:45:47

相关问题