wp8中的用户控制级别功能

时间:2014-09-14 05:56:18

标签: xaml windows-phone-8 user-controls

在我的Windows手机应用程序中,我只想使用一个MainPage.xaml页面,并根据用户活动更改其中的用户控件。但现在我不知道如何用这个实现后退功能。它存在一个按键的应用程序,但我希望它转到以前的控制。

有没有办法做到这一点?

感谢。

1 个答案:

答案 0 :(得分:1)

要处理后退按键,您可以使用以下代码:

public MainPage()
{
  InitializeComponent();

  this.BackKeyPress += MainPage_BackKeyPress;
}

void MainPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
     if (...)    // custom check to determine if the user control should be changed ...
     {
          ...    // custom code to change the user control ...
          e.Cancel = true; // Prevent application close
     }        
}

自定义代码是您的责任。您可以使用一组用户控件 - 在更改UI时将旧控件推入堆栈,按下后退键时弹出堆栈。如果堆栈为空,则允许关闭应用程序。