在我的Windows手机应用程序中,我只想使用一个MainPage.xaml
页面,并根据用户活动更改其中的用户控件。但现在我不知道如何用这个实现后退功能。它存在一个按键的应用程序,但我希望它转到以前的控制。
有没有办法做到这一点?
感谢。
答案 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时将旧控件推入堆栈,按下后退键时弹出堆栈。如果堆栈为空,则允许关闭应用程序。