更新时间:2022-04-08 22:28:51
添加 ActivationPolicy="Resume" 并不是让您的应用支持快速应用恢复所需的唯一步骤.我相信当您只设置一个属性时,您所描述的行为是正常的.我认为有几种方法可以实现快速应用恢复",但我发现这是最简单的方法.
Adding ActivationPolicy="Resume" is not the only step needed to have your app support Fast App Resume. I believe the behavior you are describing is normal when you only set that one property. I think there are a few ways to implement "Fast App Resume", but I found this to be the easiest way.
像刚才描述的那样设置激活策略,然后执行以下操作:
Set the activation policy like you just described and then do the following:
进入App.xaml.cs在App"类中添加:
Go into App.xaml.cs in the "App" class add:
private bool reset
然后您应该有一个用于初始化 RootFrame 的 InitializePhoneApplication 方法.添加这个:
You should then have a method for InitializePhoneApplication that initializes the RootFrame. Add this:
RootFrame.Navigating += RootFrame_Navigating;
RootFrame.Navigated += RootFrame_Navigated;
然后你可以去添加这些方法:
Then you can go and add those methods:
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (reset && e.IsCancelable && e.Uri.OriginalString == "/MainPage.xaml")
{
e.Cancel = true;
reset = false;
}
}
void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
reset = e.NavigationMode == NavigationMode.Reset;
}
如果您正确地实现了这一点,您的应用应该会从您所在的最后一个页面恢复.
If you implement this properly, your app should resume from the last page you were on.