首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在windows 10 UWP中处理挂起、恢复和激活

在windows 10 UWP中处理挂起、恢复和激活
EN

Stack Overflow用户
提问于 2015-07-27 08:01:20
回答 2查看 3.4K关注 0票数 8

在Windows8.1通用应用程序中,挂起/恢复模式是使用应用模板中包含的NavigationHelper.cs ans SuspensionManager.cs类处理的。这些类似乎不在windows 10 UWP应用程序中。是否有处理挂起/恢复状态的方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-28 08:13:36

社区正在开发一个有趣的框架(但我认为主要是曾傑瑞·尼克松安迪·韦格利等)。叫Template10。Template10有一个带有OnSuspendingOnResuming虚拟方法的自举器类,您可以重写这些方法。我不确定是否有使用Template10执行暂停/恢复的确切示例,但是这个想法似乎是为了使App.xaml.cs继承了这个引导程序类能够轻松地覆盖我提到的方法。

代码语言:javascript
运行
复制
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
    }
}
票数 4
EN

Stack Overflow用户

发布于 2017-03-03 12:37:25

以上解决方案只适用于安装Template10的人员。一般的解决方案是,

将这些行粘贴到App.xaml.cs的构造函数中

代码语言:javascript
运行
复制
        this.LeavingBackground += App_LeavingBackground;

        this.Resuming += App_Resuming;

它会看起来像这样

代码语言:javascript
运行
复制
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
        this.LeavingBackground += App_LeavingBackground;

        this.Resuming += App_Resuming;
    }

这些是方法,尽管您可以按TAB,它们将自动生成。

代码语言:javascript
运行
复制
    private void App_LeavingBackground(object sender, LeavingBackgroundEventArgs e)
    {

    }

    private void App_Resuming(object sender, object e)
    {

    }

LeavingBackground方法和这里没有提到的方法EnteredBackground是新添加到uwp中的。

在这些方法之前,我们将使用恢复和挂起来保存和恢复ui,但是现在推荐的工作位置是here.Also --这是应用程序恢复之前执行工作的最后一个地方。因此,在这些方法上的工作应该是小ui或其他东西,如重建值,这些都是过时的方法,在这里会影响应用程序的启动时间。

Windows开发材料Windoes dev材料2

谢谢,祝你今天愉快。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31647827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档