从我的 WP8 后台代理中,我得到了正常工作的正常 ShellToast。
但是现在有了 WP8.1,我希望能够在某些时间(晚上)发送安静的祝酒词,它应该只在这些时间出现在通知中心。我一直在关注本指南,但它似乎根本不起作用。吐司没有出现...
任何人已经得到这个工作了吗?
谢谢
我的代码:
public MainPage()
{
InitializeComponent();
SendToast();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
SendToast();
}
private void SendToast()
{
// Using the ToastText02 toast template.
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
// Retrieve the content part of the toast so we can change the text.
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
//Find the text component of the content
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
// Set the text on the toast.
// The first line of text in the ToastText02 template is treated as header text, and will be bold.
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Heading"));
toastTextElements[1].AppendChild(toastXml.CreateTextNode("Body"));
// Set the duration on the toast
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
// Create the actual toast object using this toast specification.
ToastNotification toast = new ToastNotification(toastXml);
toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(3600);
// Set SuppressPopup = true on the toast in order to send it directly to action center without
// producing a popup on the user's phone.
toast.SuppressPopup = false;
// Send the toast.
ToastNotificationManager.CreateToastNotifier().Show(toast);
}