0
 ToastTemplateType toastType = ToastTemplateType.ToastImageAndText02;
           XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(toastType);
           XmlNodeList toastText = toastXML.GetElementsByTagName("text");
           XmlNodeList toastImages = toastXML.GetElementsByTagName("image");
           toastText[0].InnerText = "Funny cat";
           toastText[1].InnerText = "This cat looks like it's trying to eat your face.";
           ((XmlElement)toastImages[0]).SetAttribute("src", "ms-appx:///Assets/washer.png");
           ((XmlElement)toastImages[0]).SetAttribute("alt", "Scary Cat Face");

           //This is the options code, which is all optional based on your needs.
           IXmlNode toastNode = toastXML.SelectSingleNode("/toast");

           ((XmlElement)toastNode).SetAttribute("duration", "long");

           XmlElement audioNode = toastXML.CreateElement("audio");

           audioNode.SetAttribute("src", "ms-appx:///Assets/beep.wav");

           //Must be used when looping audio has been selected.
           audioNode.SetAttribute("loop", "true");
           toastNode.AppendChild(audioNode);

           //You can append any text data you would like to the optional
           //launch property, but clicking a Toast message should drive
           //the user to something contextually relevant.
           ((XmlElement)toastNode).SetAttribute("launch", "<cat state='angry'><facebite state='true' /></cat>");

           ToastNotification toast = new ToastNotification(toastXML);
           ToastNotificationManager.CreateToastNotifier().Show(toast);

所以我从网页上获取了这段代码,它可以工作,但有一个细节。它播放的声音不是我想要它播放的声音...即使指定名称和资产,它看起来像是播放来自微软的声音?谢谢!

4

2 回答 2

1

显然这是 Windows 10 中的一个错误,目前还没有解决方案。 http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10.aspx

“......自定义音频不起作用。我们正在调查这个问题。ms-appx 和 ms-appdata 都不能在桌面上工作,只有 ms-appdata 在移动设备上工作。”

于 2015-08-13T04:14:06.270 回答
0

Toast 通知只能播放一组固定的系统提供的声音 - 例如,ms-winsoundevent:Notification.Mail. 如果未指定特定声音或src提供无效声音,则将播放默认声音。

可以在 MSDN 上的此文档中找到受支持声音的完整列表。

于 2013-06-12T03:42:07.513 回答