c# - 设置通知参数

标签 c# windows-phone-8.1 win-universal-app

我使用 C# 和 Windows Phone 8.1 作为通用应用程序。我可以通过以下代码从后台发送通知:

    void ShowNotification(string title, string text)
    {
        ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

        XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
        XmlNodeList textElements = toastXml.GetElementsByTagName("text");
        textElements[0].AppendChild(toastXml.CreateTextNode(title));
        textElements[1].AppendChild(toastXml.CreateTextNode(text));

        ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toastXml));
    }

我希望当用户在操作中心点击这些通知时,我在通知中编写的消息显示在我的主页中的文本 block 上,但我不知道如何设置参数来执行此操作。我在 MainPage 中使用了此代码,但参数为空:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e != null && e.Parameter != null)
        {
            Debug.WriteLine("MainPage.OnNavigatedTo.Parameter: " + e.Parameter.ToString());
        }
    }

谢谢

最佳答案

您需要指定应用程序启动参数,例如:

IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

然后在应用程序的 onlaunched 事件中,使用您获得的参数导航到主页,如下所示:

rootFrame.Navigate(typeof(MainPage), args.Arguments);

关于c# - 设置通知参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30731324/

相关文章:

c# - datagridview 中的每一行(对象)都有自己的绑定(bind)源?

c# - float.Parse 中丢失的 float 精度

c# - MVC 复选框分组

deployment - 无法使用Windows 10 Mobile Tech Preview将通用应用程序部署到手机

windows-runtime - 如何将 Frame.Navigate 设置为立即发生而没有过渡?

xaml - 将 MenuFlyout 添加到 RichEditBox UWP

c# - 服务 OnShutDown() 期间的 WCF 调用

cordova - PhoneGap 应用程序在 WP8.1 上崩溃

camera - Windows Phone 8.1 MediaCapture CapturePhotoToStorageFileAsync 内存泄漏

c# - 通过API下载soundcloud数据