[C#]从Toast打开App [英] [C#]Open App from Toast

查看:105
本文介绍了[C#]从Toast打开App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自通知中心的自适应Toast通知,我已经成功配置并从OnActivatedEvent解雇,如下图所示;

I have an Adaptive Toast Notification coming in from Notification Hub, and i have successfully configured and are firing from the OnActivatedEvent as illustrated below;

         protected override async void OnActivated(IActivatedEventArgs e)

        {

            //获取根框架$
            Frame frameFrame = Window.Current.Content as Frame;



            //处理吐司激活

            if(e.Kind == ActivationKind.ToastNotification)

            {

                VAR refreshDataTasks = GetViewModels()

                。选择(VM => vm.LoadDataAsync(真));

             &NBSP ; 等待Task.WhenAll(refreshDataTasks);

                NavigationService.NavigateToPage(typeof(NewsListPage));
$


            }




            //确保当前窗口处于活动状态

            Window.Current.Activate();

        }

        protected override async void OnActivated(IActivatedEventArgs e)
        {
            // Get the root frame
            Frame rootFrame = Window.Current.Content as Frame;

            // Handle toast activation
            if (e.Kind == ActivationKind.ToastNotification)
            {
                var refreshDataTasks = GetViewModels()
                .Select(vm => vm.LoadDataAsync(true));
                await Task.WhenAll(refreshDataTasks);
                NavigationService.NavigateToPage(typeof(NewsListPage));

            };


            // Ensure the current window is active
            Window.Current.Activate();
        }

这在应用程序打开时非常有效,但是,我希望Toast点击同时打开应用程序并浏览到该特定应用程序页面,但是当我这样做时,我收到有关初始化NavigationService的错误。

This works perfectly when the app is open, however, I would like the Toast click to also open the app and browse to that specific page, but when I do, I receive an error regarding Initializing the NavigationService.

我在网上看到很多像我一样的例子,每个人都说它有用。

I have seen many examples on the web written just like mine and everyone says it works.

如何在应用关闭时从吐司导航到某个页面? 我已尝试过PreviousExecution状态,但似乎在OnActivated事件中,NavigationService尚未初始化。

How can I navigate to a page from toast when the app was closed?  I have tried PreviousExecution state, but it appears that in the OnActivated event, NavigationService has yet to be initialized.

我该如何使用?

DWM

推荐答案

你可以试试使用框架导航到页面:

You could try to use the Frame to navigate to the page:

protected async override void OnActivated(IActivatedEventArgs args)
        {
            // Get the root frame
            Frame rootFrame = Window.Current.Content as Frame;

            // Handle toast activation
            if (args.Kind == ActivationKind.ToastNotification)
            {
                var refreshDataTasks = GetViewModels()
                .Select(vm => vm.LoadDataAsync(true));
                await Task.WhenAll(refreshDataTasks);
                rootFrame.Navigate(typeof(NewsListPage));
            };


            // Ensure the current window is active
            Window.Current.Activate();
        }

我没有内置的NavigationService.NavigateToPage UWP API。

There is no built-in NavigationService.NavigateToPage UWP API that I am aware of.

希望有所帮助。

请记住通过将有用的帖子标记为答案来关闭您的主题,然后如果您有新问题则启动新主题。请不要在同一个帖子中提出几个问题。

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于[C#]从Toast打开App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆