2015-06-09 94 views
2

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

感谢

回答

4

您需要指定应用程序启动参数,如:在应用程序的onlaunched事件

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

然后,导航与炫魅广东参数如下:

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