Introduced
Re-imagine the Windows 8 Store Apps Notice
Toast-Basic applications See http://www.cnblogs.com/webabcd/archive/2013/06/17/3139740.html
Toast-Plain Text Toast
Toast-Graphic Toast
Toast-toast's cue tone
Toast-Eject Toast as scheduled
Example
1, demo plain text toast 4 templates
Notification/toast/toastwithtext.xaml
<page x:class= "XamlDemo.Notification.Toast.ToastWithText" xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml /presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: XamlDemo.Notification.Toast "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "&
Gt <stackpanel margin= "0 0 0" > <textbox name= "lblmsg" height= "" textwrapping= "Wrap" ACCEPTSR Eturn= "True" fontsize= "14.667" margin= "0 0 0"/> <button name= "btntextbodywrap" content= "Textbod Ywrap "click=" btntextbodywrap_click_1 "margin=" 0 0 0 "/> <button name=" Bnttextheadingtextbodywra
P "content=" textheading textbodywrap "click=" bnttextheadingtextbodywrap_click_1 "margin=" 0 0 0 "/> <button name= "Bnttextheadingwraptextbody"content= "Textheadingwrap textbody" click= "bnttextheadingwraptextbody_click_1" margin= "0 0 0"/> ; Button Name= "Bnttextheadingtextbody" content= "textheading TextBody1 TextBody2" click= "Bnttextheadingtextbody_click_ 1 "margin=" 0 0 0 "/> </StackPanel> </Grid> </Page>
Notification/toast/toastwithtext.xaml.cs
* * Demo 4 templates for plain text toast * The toast XmlDocument content builder for this example takes an open source project, as shown in code: Notificationsextensions/toastcontent.cs * * XmlDocument gettemplatecontent (toasttemplatetype type)-Get the system-supported Toast template * toasttemplatetype.toasttext01, ToastTempl atetype.toasttext02, toasttemplatetype.toasttext03, toasttemplatetype.toasttext04 * * using NotificationsExtensions.
Toastcontent;
Using Windows.UI.Notifications;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls; Namespace XamlDemo.Notification.Toast {public sealed partial class Toastwithtext:page {public Toastwit Htext () {this.
InitializeComponent (); } private void Btntextbodywrap_click_1 (object sender, RoutedEventArgs e) {IToastText01 T
Emplatecontent = toastcontentfactory.createtoasttext01 (); TemplateContent.TextBodyWrap.Text = "I am the notification body, the line can be changed, up to three lines." I am the notification body, the line can be changed, up to three lines. I am the notification body, the line can be changed, up to three lines.
"; Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingtextbodywrap_click_1 (object sender, RoutedEventArgs e) {ITo
astText02 TemplateContent = toastcontentfactory.createtoasttext02 (); TemplateContent.TextHeading.Text = "I am the notification title, you cannot wrap." I am the notification title, you can not change lines.
"; TemplateContent.TextBodyWrap.Text = "I am the notification body, the line can be changed, up to two lines." I am the notice body, can change lines, up to two lines.
";
Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingwraptextbody_click_1 (object sender, RoutedEventArgs e) {ITo astText03 TemplAtecontent = toastcontentfactory.createtoasttext03 (); TemplateContent.TextHeadingWrap.Text = "I am the notice title, can be wrapped, up to two lines." I am the notice title, the line can be changed, up to two lines.
"; TemplateContent.TextBody.Text = "I am the notification body, you can not change lines." I am the notification body, you can not change lines.
";
Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingtextbody_click_1 (object sender, RoutedEventArgs e) {ITOASTT
ext04 TemplateContent = toastcontentfactory.createtoasttext04 (); TemplateContent.TextHeading.Text = "I am the notification title, you cannot wrap." I am the notification title, you can not change lines.
"; TemplateContent.TextBody1.Text = "I am the notice body 1, can not wrap line." I am the notice body 1, can not wrap line.
"; TemplateContent.TextBody2.Text = "I am the notice body 2, can not wrap line." I am the notice body 2, can not wrap line.
";
Itoastnotificationcontent toastcontent = TemplateContent; Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); }
}
}
2, demo graphics and text Toast of the 4 templates
Notification/toast/toastwithimagetext.xaml
<page x:class= "XamlDemo.Notification.Toast.ToastWithImageText" xmlns= "http://schemas.microsoft.com/winfx/2006 /xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: XamlDemo.Notification.Toast "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "&
Gt <stackpanel margin= "0 0 0" > <textbox name= "lblmsg" height= "" textwrapping= "Wrap" ACCEPTSR Eturn= "True" fontsize= "14.667" margin= "0 0 0"/> <button name= "btntextbodywrap" content= "Textbod Ywrap "click=" btntextbodywrap_click_1 "margin=" 0 0 0 "/> <button name=" Bnttextheadingtextbodywra
P "content=" textheading textbodywrap "click=" bnttextheadingtextbodywrap_click_1 "margin=" 0 0 0 "/> <button name= "BnttextheadingwraptextbOdy "content=" Textheadingwrap textbody "click=" bnttextheadingwraptextbody_click_1 "margin=" 0 0 0 "/> <button name= "Bnttextheadingtextbody" content= "textheading TextBody1 TextBody2" click= Click_1 "margin=" 0 0 0 "/> </StackPanel> </Grid> </Page>
Notification/toast/toastwithimagetext.xaml.cs
* * Demo graphics and text toast 4 templates (note: The picture can not be greater than 1024*1024 pixels, not greater than 200KB) * The toast XmlDocument content builder for this example uses an open source project, as specified in code: Notificationse Xtensions/toastcontent.cs * * XmlDocument gettemplatecontent (toasttemplatetype type)-Get system-supported Toast templates * Toasttem platetype.toastimageandtext01, toasttemplatetype.toastimageandtext02, toasttemplatetype.toastimageandtext03,
toasttemplatetype.toastimageandtext04 * Note: Pictures can come from the package, can come from the application Data (only supports the reference to the local picture file), can be from an HTTP remote address
* * using Notificationsextensions.toastcontent;
Using System;
Using Windows.UI.Notifications;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls; Namespace XamlDemo.Notification.Toast {public sealed partial class Toastwithimagetext:page {public Toa Stwithimagetext () {this.
InitializeComponent (); } private void Btntextbodywrap_click_1 (object sender, RoutedEventArgs e) {Itoastimageand Text01 TemplateContent = toastcontentfactory.CREATETOASTIMAGEANDTEXT01 (); TemplateContent.TextBodyWrap.Text = "I am the notification body, the line can be changed, up to three lines." I am the notification body, the line can be changed, up to three lines. I am the notification body, the line can be changed, up to three lines.
"; TEMPLATECONTENT.IMAGE.SRC = "Assets/logo.png";
Use the file in the package as a notice picture templateContent.Image.Alt = "AltText";
Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingtextbodywrap_click_1 (object sender, RoutedEventArgs e) {ITo
astImageAndText02 TemplateContent = toastcontentfactory.createtoastimageandtext02 (); TemplateContent.TextHeading.Text = "I am the notification title, you cannot wrap." I am the notification title, you can not change lines.
"; TemplateContent.TextBodyWrap.Text = "I am the notification body, the line can be changed, up to two lines." I am the notice body, can change lines, up to two lines.
"; TEMPLATECONTENT.IMAGE.SRC = "Ms-appx:///assets/logo.png";
Use the file in the package as a notification picture TemplateContent.Image.Alt = "AltText";
Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingwraptextbody_click_1 (object sender, RoutedEventArgs e) {ITo
astImageAndText03 TemplateContent = toastcontentfactory.createtoastimageandtext03 (); TemplateContent.TextHeadingWrap.Text = "I am the notice title, can be wrapped, up to two lines." I am the notice title, the line can be changed, up to two lines.
"; TemplateContent.TextBody.Text = "I am the notification body, you can not change lines." I am the notification body, you can not change lines.
"; TEMPLATECONTENT.IMAGE.SRC = "Ms-appdata:///local/logo.png";
Use application Data inside the file as a notification picture (note: support only local picture) TemplateContent.Image.Alt = "AltText";
Itoastnotificationcontent toastcontent = TemplateContent; Toastnotification toast = toastcontent.crEatenotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast);
Lblmsg.text = Toastcontent.getcontent (); } private void Bnttextheadingtextbody_click_1 (object sender, RoutedEventArgs e) {Itoasti
mageAndText04 TemplateContent = toastcontentfactory.createtoastimageandtext04 (); TemplateContent.TextHeading.Text = "I am the notification title, you cannot wrap." I am the notification title, you can not change lines.
"; TemplateContent.TextBody1.Text = "I am the notice body 1, can not wrap line." I am the notice body 1, can not wrap line.
"; TemplateContent.TextBody2.Text = "I am the notice body 2, can not wrap line." I am the notice body 2, can not wrap line.
";
TEMPLATECONTENT.IMAGE.SRC = "http://pic.cnblogs.com/avatar/a14540.jpg?id=24173245";
Use remote file as notification picture templateContent.Image.Alt = "AltText";
Itoastnotificationcontent toastcontent = TemplateContent;
Toastnotification toast = toastcontent.createnotification (); Toastnotificationmanager.createtoastnotifier ().
Show (toast); lblmsg.text = toastcontent.getcontent (); }
}
}
3. Demo Toast's cue tone
Notification/toast/toastwithsound.xaml
<page x:class= "XamlDemo.Notification.Toast.ToastWithSound" xmlns= "Http://schemas.microsoft.com/winfx/2006/xam L/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: XamlDemo.Notification.Toast "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "&
Gt <stackpanel margin= "0 0 0" > <textbox name= "lblmsg" height= "" textwrapping= "Wrap" ACCEPTSR Eturn= "True" fontsize= "14.667" margin= "0 0 0"/> "<textblock text=" notification beep list "margin=" 0 0 0 "/&G
T <listbox name= "ListBox" selectionchanged= "listbox_selectionchanged_1" margin= "0 0" > <listbo Xitem content= "Default"/> <listboxitem content= "Mail"/> Content
= "SMS"/><listboxitem content= "IM"/> <listboxitem content= "Reminder"/> M content= "Loopingcall"/> <listboxitem content= "LoopingCall2"/> <listboxitem content= "Loopingalarm"/> <listboxitem content= "LoopingAlarm2"/> <listboxite M content= "silent"/> </ListBox> </StackPanel> </Grid> </Page>