Geo*_*oué 11 toast windows-phone-8.1 win-universal-app
我想为Windows Phone 8.1开发一个包含本地"通知"的通用应用程序.
我想要做的是在吐司控制的扭结中向用户显示所有消息(错误,信息,警告).一切都在本地完成,无需通过标准通知系统.有几个系统适用于Windows Phone 8:
但是不可能在Windows Phone 8.1项目中包含这些库.
有没有人知道另一种显示"本地"祝酒词的方法?
Geo*_*oué 25
在@msimons响应和以下网址的帮助下:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx我成功显示了我的通知.
对于那些需要它的人来说,这是我的最终方法:
private void ShowToastNotification(String message)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
// Set Text
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode(message));
// Set image
// Images must be less than 200 KB in size and smaller than 1024 x 1024 pixels.
XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///Images/logo-80px-80px.png");
((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo");
// toast duration
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "short");
// toast navigation
var toastNavigationUriString = "#/MainPage.xaml?param1=12345";
var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
toastElement.SetAttribute("launch", toastNavigationUriString);
// Create the toast notification based on the XML content you've specified.
ToastNotification toast = new ToastNotification(toastXml);
// Send your toast notification.
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
Run Code Online (Sandbox Code Playgroud)
我在通用应用程序windows phone 8.1上测试过.
并且不要忘记编辑"Package.appxmanifest"并激活通知.在您的应用程序的package.appxmanifest文件中声明了引发Toast通知的功能.如果使用Microsoft Visual Studio清单编辑器,只需在"应用程序"选项卡的"通知"部分中将"支持Toast"选项设置为"是".
您可以使用应用运行时显示的本地通知.
ToastTemplateType toastTemplateXml = ToastTemplateType.ToastImageAndText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateXml);
Run Code Online (Sandbox Code Playgroud)
然后,您需要填充返回的XML GetTemplateContent
<toast>
<visual>
<binding template="ToastImageAndText01">
<image id="img" src=""/>
<text id="txt"></text>
</binding>
</visual>
</toast>
Run Code Online (Sandbox Code Playgroud)
在XML DOM中提供吐司的内容.该图像仅适用于Windows 8.1.
指定它的启动参数
((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"1\",\"param2\":\"2\"}");
Run Code Online (Sandbox Code Playgroud)
创建toast对象:
ToastNotification toast = new ToastNotification(toastXml);
Run Code Online (Sandbox Code Playgroud)
最后展示吐司.
ToastNotificationManager.CreateToastNotifier().Show(toast);
Run Code Online (Sandbox Code Playgroud)
此外,如果您想使用第三方控件来显示吐司,那么您可以考虑编写Windows Phone 8.1 Silverlight应用程序.
| 归档时间: |
|
| 查看次数: |
10574 次 |
| 最近记录: |