Handling suspend, resume, and activation in windows 10 UWP

前端 未结 2 1934
终归单人心
终归单人心 2021-02-15 17:30

In the windows 8.1 universal apps, the suspend/resume modes were handled using the NavigationHelper.cs ans SuspensionManager.cs classes included in the

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-15 18:07

    There's an interesting framework being developed by the community (but mostly I think Jerry Nixon, Andy Wigley etc.) called Template10. Template10 has a Bootstrapper class with OnSuspending and OnResuming virtual methods that you can override. I am not sure that there's an exact example of doing suspension/resuming yet with Template10, but the idea seems to be to make App.xaml.cs inherit from this Bootstrapper class so you can easily override the methods I mentioned.

    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(null);
        }
    
        public override Task OnSuspendingAsync(object s, SuspendingEventArgs e)
        {
            // handle suspending
        }
    
        public override void OnResuming(object s, object e)
        {
            // handle resuming
        }
    }
    
        

    提交回复
    热议问题