在Metro App中显示Toast notification
?Toast notification是向用戶顯示一些有關(guān)App的即時消息。具體Toast notification是什么可以參考
?http://msdn.microsoft.com/en-us/library/windows/apps/hh465360(v=VS.85).aspx
?創(chuàng)建Toast notification步驟:
?1.在Package.appxmanifest文件中設(shè)置ToastCapable="true",否則Toast Notification不能顯示。
? <VisualElements? ForegroundText="light" BackgroundColor="#000000" ToastCapable="true">
? ForegroundText標(biāo)簽表示Toast notification消息文字的樣式(有dark和light兩種),BackgroundColor
? 標(biāo)簽表示Toast notification的背景顏色。
?2.下面是顯示Toast notification的代碼:
??private void ShowToast()
??{
????? // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing
????? // the toast XML
????? XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);
????? XmlElement xe = toastXml.CreateElement("title");
????? // You can use the methods from the XML document to specify all of the
????? // required parameters for the toast
????? XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
????? for (uint i = 0; i < stringElements.Length; i++)
????? {
???stringElements.Item(i).AppendChild(toastXml.CreateTextNode("Pressed Screenshot key !"));
????? }
????? // Create a toast from the Xml, then create a ToastNotifier object to show
????? // the toast
????? ToastNotification toast = new ToastNotification(toastXml);
????? // If you have other applications in your package, you can specify the AppId of
????? // the app to create a ToastNotifier for that application
????? ToastNotificationManager.CreateToastNotifier().Show(toast);
??}
?完成上面兩步后,調(diào)用ShowToast方法就會在右下角顯示一個Toast notification。
總結(jié)
以上是生活随笔為你收集整理的在Metro App中显示Toast notification的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC INI文件读写 和 GetProf
- 下一篇: Metro App中使用Timer