在Windows8.1通用应用程序中,挂起/恢复模式是使用应用模板中包含的NavigationHelper.cs ans SuspensionManager.cs类处理的。这些类似乎不在windows 10 UWP应用程序中。是否有处理挂起/恢复状态的方法?
发布于 2015-07-28 08:13:36
社区正在开发一个有趣的框架(但我认为主要是曾傑瑞·尼克松安迪·韦格利等)。叫Template10。Template10有一个带有OnSuspending和OnResuming虚拟方法的自举器类,您可以重写这些方法。我不确定是否有使用Template10执行暂停/恢复的确切示例,但是这个想法似乎是为了使App.xaml.cs继承了这个引导程序类能够轻松地覆盖我提到的方法。
sealed partial class App : Common.BootStrapper
{
    public App()
    {
        InitializeComponent();
        this.SplashFactory = (e) => null;
    }
    public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
    {
        // start the user experience
        NavigationService.Navigate(typeof(Views.MainPage), "123");
        return Task.FromResult<object>(null);
    }
    public override Task OnSuspendingAsync(object s, SuspendingEventArgs e)
    {
        // handle suspending
    }
    public override void OnResuming(object s, object e)
    {
        // handle resuming
    }
}发布于 2017-03-03 12:37:25
以上解决方案只适用于安装Template10的人员。一般的解决方案是,
将这些行粘贴到App.xaml.cs的构造函数中
        this.LeavingBackground += App_LeavingBackground;
        this.Resuming += App_Resuming;它会看起来像这样
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
        this.LeavingBackground += App_LeavingBackground;
        this.Resuming += App_Resuming;
    }这些是方法,尽管您可以按TAB,它们将自动生成。
    private void App_LeavingBackground(object sender, LeavingBackgroundEventArgs e)
    {
    }
    private void App_Resuming(object sender, object e)
    {
    }LeavingBackground方法和这里没有提到的方法EnteredBackground是新添加到uwp中的。
在这些方法之前,我们将使用恢复和挂起来保存和恢复ui,但是现在推荐的工作位置是here.Also --这是应用程序恢复之前执行工作的最后一个地方。因此,在这些方法上的工作应该是小ui或其他东西,如重建值,这些都是过时的方法,在这里会影响应用程序的启动时间。
谢谢,祝你今天愉快。
https://stackoverflow.com/questions/31647827
复制相似问题