我有一个应用程序,当应用程序被逻辑删除时,我想在主屏幕上重新启动应用程序,使其处于“新”状态。
但是在默认情况下,wp7框架想要导航回您离开的页面。
如何停止这种行为?
发布于 2012-03-27 15:41:12
嗯,这就是我想出来的,就像Shahar所说的,它很粗糙(但确实有效):
在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()似乎也不能取消。在第一个导航之后,它导航到了我的起始页面。在nav完成之后,它会从后台堆栈中删除所有条目。
它可以工作,但从tombstone返回时会有明显的延迟(1 -2秒)。
发布于 2012-03-27 10:55:14
你不能真的用一些很大的hack来做到这一点。这是我个人唯一能想到的方法--也许还有其他的方法。
NavigationService.RemoveBackEntry直到你到达你的第一个页面。我强烈建议你重新考虑你的应用流程--这是一个相当糟糕的魔力。
https://stackoverflow.com/questions/9881365
复制相似问题