【问题标题】:Set parameter to notification设置通知参数
【发布时间】:2015-06-09 11:55:32
【问题描述】:

我使用 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));
    }

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

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

谢谢

【问题讨论】:

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


    【解决方案1】:

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

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

    然后在应用的onlaunched事件中,使用您得到的参数导航到主页:

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

    【讨论】:

      猜你喜欢
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 2023-02-09
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多