windows-phone-7 - 当应用程序从墓碑恢复时如何阻止导航?

标签 windows-phone-7

我有一个应用程序,当该应用程序被逻辑删除时,我想在其主屏幕上以"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/

相关文章:

c# - 我的 WP7 对象在哪里?

c# - 我需要什么来为这个游戏创建这个控件? (像管道)

c# - Windows Phone 7.1 模拟器不加载应用程序

video - 如何在 Windows Phone 7 上将屏幕录制为视频?

c# - 不使用 PrepareMethod 在运行时对代码进行预编译

c# - Windows Phone 7 测试的最佳模拟库

c# - XAML 应用程序工作流是什么样的

c# - 是否有适用于 Windows Phone 7 的免费条形码扫描仪 SDK 可以在我的应用程序中使用?

wpf - 多个绑定(bind) ViewModel 到 View MVVM

windows-phone-7 - Windows Phone 7 游戏引擎?