Windows 8 Store Apps Learning (34) Notice: Toast demo, Tile demo, Badge demo

Source: Internet
Author: User
Tags constructor tostring xmlns

Introduced

Re-imagine the Windows 8 Store Apps Notice

Toast-Application of notifications

Application of Tile-porcelain paste

Badge-Application of the coat of arms

Badge-Polling the service side to update Badge notifications

Example

1, the basic application of demo toast

Notification/toast/demo.xaml

<page x:class= "XamlDemo.Notification.Toast.Demo" xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presenta tion "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" Using:XamlDemo.Notification.Toast "x" Mlns:d= "http://schemas.microsoft.com/expression/blend/2008" xmlns:mc= "http://schemas.openxmlformats.org/ markup-compatibility/2006 "mc:ignorable=" D "> <stackpanel margin=" 0 0 0 "> <textbo
    
        X name= "lblmsg" height= "textwrapping=" Wrap "acceptsreturn=" True "fontsize=" 14.667 "margin=" 0 0 0 "/> <!--pop-up notifications (notifications show shorter time)--> <button name= "Btnshorttoast" content= "short Toast" click= "Btnshorttoast_click_1 "margin=" 0 0 0 "/> <!--pop-up notification (notification displayed longer)--> <button name=" Btnlongtoast "content=" Long T Oast "click=" btnlongtoast_click_1 "margin=" 0 0 0 "/> <textblock name=" lblstatus "fontsize=" 14.667 "M argin= "0 0 0"/> </stAckpanel> </Page> 

Notification/toast/demo.xaml.cs

* * TOAST-Notification * TOASTNOTIFICATION-TOAST notification * content-toast content, XmlDocument type of data, read only, it needs to be specified in the constructor * E Xpirationtime-toast the expiration of the notification, that is, if the system does not show the corresponding Toast notification after the time specified in this property, then do not show the * activated-event triggered when the user clicks the notification * DISMI Ssed-event triggered when notification disappears (event parameter Toastdismissedeventargs) * Failed-Notification of events triggered when a failure is displayed * * Toastdismissedeventargs-toast disappears         Event parameter * Reason-the reason for the disappearance of the notification (Windows.UI.Notifications.ToastDismissalReason enum) * usercanceled-User shutdown notification * Applicationhidden-Toastnotifier.hide () Close notification * timedout-automatic shutdown notification (short notice 7 seconds, long notice 25 seconds) * * Toastnot Ificationmanager-toast Notification Manager * Createtoastnotifier ()-Creates a TOAST notification that returns the Toastnotifier type of data * Createtoastnoti Fier (String ApplicationID)-Creates a TOAST notification for the specified app (the other app in the same package is specified here.)     Note: A package can have more than one app, but cannot be audited by the store at the moment * toastnotifier-toast notice * Show ()-Displays the specified toastnotification * Hide ()-hides the specified toastnotification * Setting-gets notification settings (WINDOWS.Ui.notifications.notificationsetting enum) * Enabled-Notification can be displayed * disabledforapplication-user disabled notification for this application * Disabledforuser-The user has disabled all notifications for this account on this computer * Disabledbygrouppolicy-administrators have banned all notifications on this computer through Group Policy * DISABLEDBYM Anifest-application does not enable Toast notification in package.appxmanifest (corresponding to the small logo in the application UI) * * NOTE: * Current system supports 8 sets of Toast templates: see: Toast 
 Withtext.xaml and Toastwithimagetext.xaml * Toast notice the application logo in the lower right corner, with the small logo configured in Package.appxmanifest, that is, the 30*30 pixel logo * cannot be run in an emulator
* * using Notificationsextensions.toastcontent;
Using System;
Using Windows.Data.Xml.Dom;
Using Windows.UI.Core;
Using Windows.UI.Notifications;
Using Windows.UI.Xaml;
    
Using Windows.UI.Xaml.Controls;
            Namespace XamlDemo.Notification.Toast {public sealed partial class Demo:page {public Demo () { This.
        InitializeComponent ();
            }//Pop-up short notice private void Btnshorttoast_click_1 (object sender, RoutedEventArgs e) { With one openThe Toast constructor for the source creates the toastnotification, which is implemented in the following: Notificationsextensions/toastcontent.cs IToastText01 TemplateContent
            = 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.
            "; Templatecontent.duration = Toastduration.short;
            Short notice, default value itoastnotificationcontent toastcontent = TemplateContent;
    
            Toastnotification toast = toastcontent.createnotification (); Monitor Toastnotification related event toast.
            Activated + = toast_activated; Toast.
            Failed + = toast_failed; Toast.
    
            Dismissed + = toast_dismissed;
            Eject the specified notification toastnotifier toastnotifier = Toastnotificationmanager.createtoastnotifier ();
    
            Toastnotifier.show (toast);
            Lblstatus.text + = "notificationsetting:" + toastNotifier.Setting.ToString ();
    
            Lblstatus.text + = Environment.NewLine; Displays the toast of thisXML lblmsg.text = Toastcontent.getcontent ();
            }//popup long notification private void Btnlongtoast_click_1 (object sender, RoutedEventArgs e) { XML var toastxmlstring = "<toast duration= ' long ' >" + "for manually constructing Toast notifications
                               <visual version= ' 1 ' > "+" <binding template= ' ToastText01 ' > " + "<text id= ' 1" > I am the notification body, can be changed lines, 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.
                               </text> "+" </binding> "+" </visual> "
    
            + "<audio silent= ' true '/>" + "</toast>";
            Converts the string to XmlDocument xmldocument toastdom = new XmlDocument ();
    
            Toastdom.loadxml (toastxmlstring);
  Instantiate toastnotification toastnotification toast = new Toastnotification (toastdom);  
            Monitor Toastnotification related event toast.
            Activated + = toast_activated; Toast.
            Failed + = toast_failed; Toast.
    
            Dismissed + = toast_dismissed;
            Eject the specified notification toastnotifier toastnotifier = Toastnotificationmanager.createtoastnotifier ();
    
            Toastnotifier.show (toast);
            Lblstatus.text + = "notificationsetting:" + toastNotifier.Setting.ToString ();
    
            Lblstatus.text + = Environment.NewLine;
        Displays the XML lblmsg.text = toastxmlstring for this toast; } async void toast_dismissed (toastnotification sender, Toastdismissedeventargs args) {AW Ait Dispatcher.runasync (Coredispatcherpriority.normal, () => {lblstatus.text = "Toast.dis Missed: "+ args."
                Reason.tostring ();
            Lblstatus.text + = Environment.NewLine;
        }); } async void Toast_failed (toastnotification sender, ToasTfailedeventargs args) {await dispatcher.runasync (Coredispatcherpriority.normal, () => {Lblstatus.text + = "toast.failed:" + args.
                Errorcode.tostring ();
            Lblstatus.text + = Environment.NewLine;
        }); } async void toast_activated (toastnotification sender, Object args) {await dispatcher.ru Nasync (Coredispatcherpriority.normal, () => {lblstatus.text + = "toast.activated:" + Sende
                R.content.getxml ();
            Lblstatus.text + = Environment.NewLine;
        }); }
    }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.