如果回退到前一个页面是一个不合理的行为,比如打开了一个弹出框,用户可能会按下返回键来关闭弹出框。在这种情况下,他们的本意不是离开应用程序,“返回”仅仅意味着摆脱弹出的对话框。重写有两种方法,第一种是重写OnBackKeyPress事件,第二种是重写PhoneApplicationPage_BackKeyPress事件。

  下面是在Windows Phone中重写返回键的代码

  1、重写OnBackKeyPress事件


protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)


        {


            e.Cancel = true;


            if (MessageBox.Show("保存工程??", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)


            {


                App.Intilize();


                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));


            }


        }


  2、重写PhoneApplicationPage_BackKeyPress事件
  添加事件:

  windows phone7 学习笔记04——重写返回键

  重写:

  windows phone7 学习笔记04——重写返回键

 

  这些要注意的是,不能忘记了取消原来的返回键操作,即不要忘了e.Cancel = true。



相关文章:

  • 2022-02-16
  • 2022-02-25
  • 2021-12-20
  • 2021-10-28
  • 2021-09-28
  • 2021-07-04
猜你喜欢
  • 2022-02-07
  • 2021-09-14
  • 2021-11-14
  • 2022-12-23
  • 2021-07-31
  • 2021-12-12
  • 2021-08-03
相关资源
相似解决方案