我有一个应用程序,当该应用程序被逻辑删除时,我想在其主屏幕上以"new"状态再次重新启动该应用程序。
但默认情况下,wp7 框架希望将您导航回您离开的页面。
如何阻止这种行为?
最佳答案
呃,这就是我想出的,就像沙哈尔所说,它很hacky(但确实有效):
在App.xaml.cs中
bool hasLaunched;
private void Application_Launching(object sender, LaunchingEventArgs e)
{
hasLaunched = true;
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
if (!hasLaunched) // recovering from a tombstone
GlobalNavigationService.ToMainPage();
hasLaunched = true;
}
在 GlobalNavigationService 类中:
public static async void ToMainPage()
{
//CurrentFrame.StopLoading();
await Observable.FromEventPattern<NavigationEventArgs>(CurrentFrame, "Navigated").Take(1).ToTask();
SafelyNavigateTo("/ZuneSlotMachine;component/Views/Main/MainPage.xaml");
await Observable.FromEventPattern<NavigationEventArgs>(CurrentFrame, "Navigated").Take(1).ToTask();
while (CurrentFrame.BackStack.Count() > 0)
CurrentFrame.RemoveBackEntry();
}
基本上,它会等待第一次导航发生,即使通过调用 CurrentFrame.StopLoading() 似乎也无法取消该导航。第一次导航后,它导航到我的起始页面。导航完成后,它会从后台删除所有条目。
它可以工作,但是从墓碑返回时有明显的延迟(1 - 2 秒)。
关于windows-phone-7 - 当应用程序从墓碑恢复时如何阻止导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9881365/