People who are familiar with or know the WP system know that WP's TOAST,TOAST (toast) notifications are the cue boxes that pop up on top of the screen, designed for use with badges, tile notifications, and UI in the app, but it's not messagedialog. Say simple it can pop up when the app is opened or pop up when the app is closed, not important information don't use toast.
To use a toast, you must first set it in Package.appxmanifest
Then, set "Support toast Notification" to "yes" if you are using the English version of VS, "application"-"notifications"-"toast capable", set to "Yes".
Next, a small example is posted:
//parameters are enumerations that are used to obtain the system's templateXmlDocument Toastxml =toastnotificationmanager.gettemplatecontent (toasttemplatetype.toasttext01);//Here are some of the XML operations, not much to explainXmlNodeList elements = Toastxml.getelementsbytagname ("text"); elements[0]. AppendChild (Toastxml.createtextnode ("a sample Toast"));//Create and initialize, and then displayToastnotification toast =Newtoastnotification (Toastxml); Toastnotificationmanager.createtoastnotifier (). Show (toast);
If you want to see the XML in the template, you can do the following
var Template = Toastxml.getxml ();
The XML for the ToastText01 template in the example above is
OK, let's review the steps to create a toast:
1. We have to get the template first, of course, we can also use a string to spell out the template, notice that the node seems to be fixed, do not recognize the custom
//The value of the template property in the binding must be an existing system template that must be the same as the enumeration value, and if it is something else, it will pop up the new notification//as for how to customize the template I do not know, have to know, please leave a messagestringToastxml ="<toast>"+"<visual>"+"<binding template= ' ToastText01 ' >"+"<text id= ' 1 ' >"+datetime.now.tostring () +"</text>"+"</binding>"+"</visual>"+"</toast>"; XmlDocument Toastxml=NewXmlDocument (); Toastxml.loadxml (Toastxml); Toastnotification Toast=Newtoastnotification (Toastxml); Toastnotificationmanager.createtoastnotifier (). Show (toast);
2. Fill in the content you want to eject
3. Create a Toast Object
4. Eject
When the app leaves the foreground, we can use a regular toast (Scheduledtoastnotification Class) to pop up the message, by preset a point in time, and then pop up the toast notification at that point, if the app isn't running in the foreground, You can go directly to the current app by clicking the toast Notification.
XmlDocument Toastxml =toastnotificationmanager.gettemplatecontent (toasttemplatetype.toasttext01); XmlNodeList Elements= Toastxml.getelementsbytagname ("text"); elements[0]. AppendChild (Toastxml.createtextnode ("a sample Toast"));//It's a timed toast .//The basic steps are the same, the difference is that we need to preset a time and call the Popup method is differentDateTime dt = DateTime.Now.AddSeconds (5); Scheduledtoastnotification Toast=Newscheduledtoastnotification (toastxml, DT); Toastnotificationmanager.createtoastnotifier (). Addtoschedule (toast); //This is a toast that the foreground runs to eject//toastnotification toast = new Toastnotification (toastxml);//Toastnotificationmanager.createtoastnotifier (). Show (toast);
The effect is as follows:
Okay, here's a toast.
windowsphone8.1 Toast Notification of learning notes