Uncle bird developed Windows 8 (2): Tile (tile) and tile notification

Source: Internet
Author: User

First, let's take a look at the notification types in Win8: refer to the msdn overview of tile, screen lock, toast, and secondary tile.

1. tile notification: An icon (310x150 in width) and a (150x150 in width) on the homepage after the program is installed )), however, we can send some notification messages to him in the background.

2. screen lock reminder: A. The first is to display the numbers (0-99) and fonts (defined by the system) in the lower right corner of the tile)

B. The second is the screen lock reminder on the computer screen.

3. Secondary tile notification: the secondary tile means that you can pin the specific content or experience in the application to the "Start" screen so that you can directly access the content or experience. For example, QQ can fix a common contact on the desktop, and then click to enter the chat mode.

4. Toast notification: This is a notification sent in the upper-right corner of the screen.

Next, let's take a look at the types of notifications that can be sent: You can refer to msdn to select a notification delivery method.

1. Local notification

2. Plan notification

3. Periodic notifications

4. push notifications

Today we will discuss the local tile notifications:

I. How to set the default Tile

You can open the package. appxmanifest file of the project. In this file, we can set

 

Note:

First display name: It will be displayed in the prompt box when the system is uninstalled (maybe there are other places I haven't found)

The second display name is used with the short name above to specify the logo to display. (For example, if only the standard logo is specified in the display name, the short name is not displayed in the lower left corner of the logo)

The logo must be set. The wide logo and small logo are optional. If the wide logo is not set, the zoom button will not appear in the app bar of the homepage, the logo will be displayed in the lower left corner when we send the notification (the installation program will not be displayed at the beginning, and I do not know why I may have read it wrong)

2. Send a local notification to tile

1. Use xmldocument to implement

// Send a local tile to update private void button_click_1 (Object sender, routedeventargs e) {// obtain the XML xmldocument tilexml = tileupdatemanager of the specified template image block. gettemplatecontent (tiletemplatetype. tilewideimageandtext01); tbxml. TEXT = tilexml. getxml (); // you can view different XML of each template. // set the text xmlnodelist textnode = tilexml for the XML node. getelementsbytagname ("text"); textnode [0]. innertext = "this is a tile I created, which includes an image and a text line up to two"; // Add the image xmlnodelist imagenode = tilexml. getelementsbytagname ("image"); (xmlelement) imagenode [0]). setattribute ("src", "Ms-appx: // images/quanbu.png"); (xmlelement) imagenode [0]). setattribute ("Alt", "wide graph"); // create a tile notification object tilenotification = new tilenotification (tilexml); // update tile tileupdatemanager. createtileupdaterforapplication (). update (tilenotification );}

 

Note:

1. First, we need to use the gettemplatecontent () method of tileupdatemanager to obtain the XML document of the tile template,

2. assign values to corresponding nodes through XML knowledge.

3. Then we will create a tile notification object tilenotification.

4. Finally, send a tile update

 2. Send both wide notifications and square notifications.

The above Code only creates a wide notification. When we set the notification icon to a square on the homepage, because the system does not have any practical notifications, therefore, for better experience, we 'd better set both square and wide notifications when sending notifications.

// Use xmldom to add both the extended and square notification private void button_click_7 (Object sender, routedeventargs e) {// wide-form xmldocument tilexml = tileupdatemanager. gettemplatecontent (tiletemplatetype. tilewidetext03); xmlnodelist textnode = tilexml. getelementsbytagname ("text"); textnode [0]. innertext = "a string that can contain up to three lines of large text with automatic line breaks"; // square xmldocument squarexml = tileupdatemanager. gettemplatecontent (tiletemplatetype. tilesquaretext04); xmlnodelist squarenode = squarexml. getelementsbytagname ("text"); squarenode [0]. appendchild (squarexml. createtextnode ("A text string that covers up to four rows"); // assign ixmlnode node = tilexml to the text node. importnode (squarexml. getelementsbytagname ("binding "). item (0), true); // obtain the binding node and Its subnode tilexml in the square XML text. getelementsbytagname ("visual") [0]. appendchild (node); // Add content from the square binding node to the visual node // create a local tile notification tilenotification = new tilenotification (tilexml); // update the local notification tileupdatemanager. createtileupdaterforapplication (). update (tilenotification );}

Note:

This implementation is not hard to understand. We need to add two notifications, that is, adding two bindings in the visual file of the XML document, mainly XML operations.

3. Use the icationicationsextensions Library

The function of this library is that we can use the same object and attribute to operate the notification document content.

// Use icationsextensions private void button_click_6 (Object sender, routedeventargs e) {// obtain the tile content itilewideimageandtext01 tilecontent = tilecontentfactory. createtilewideimageandtext01 (); tilecontent. textcaptionwrap. TEXT = "use icationicationsextension to send local notifications"; tilecontent. image. src = "MS-appx: // images/quanbu.png"; tilecontent. image. alt = "wide logo"; // Add a square notification itilesquaretext02 tilesquarecontetn = tilecontentfactory. createtilesquaretext02 (); tilesquarecontetn. textheading. TEXT = "title"; tilesquarecontetn. textbodywrap. TEXT = "here you can add up to three lines of text"; // bind the square notification content to the tilecontent in the wide notification. squarecontent = tilesquarecontetn; // create tile notification tilenotification = tilecontent. createnotification (); tileupdatemanager. createtileupdaterforapplication (). update (tilenotification );}

Note:

1. First, we need to reference A icationicationsextensions. winmd file to the project, and then add reference to it (refer to the notificationsextensions library of msdn)

2. In the code, we can use the tilecontentfactory class in the code to obtain the object we need to operate on, and then set the relevant attributes.

3. This Code sets tilecontent. squarecontent = tilesquarecontetn for both width and square notifications;

 

4. Enable notification queue

The above shows only one notification example. Let's take a look at multiple notification examples,

First, we need to allow the notification queue

Protected override void onnavigatedto (navigationeventargs e) {// enable the notification queue tileupdatemanager. createtileupdaterforapplication (). enablenotifquequeue (true );}

Can I add multiple notifications?

// Use the notification queue private void button_click_4 (Object sender, routedeventargs e) {for (INT I = 1; I <= 7; I ++) {// obtain the XML xmldocument tilexml = tileupdatemanager of the specified template. gettemplatecontent (tiletemplatetype. tilewideimageandtext01); tbxml. TEXT = tilexml. getxml (); // you can view different XML of each template. // set the text xmlnodelist textnode = tilexml for the XML node. getelementsbytagname ("text"); textnode [0]. innertext = string. format ("this is the {0} tile notification", I. toS Tring (); // Add the image xmlnodelist imagenode = tilexml. getelementsbytagname ("image"); (xmlelement) imagenode [0]). setattribute ("src", "Ms-appx: // images/quanbu.png"); (xmlelement) imagenode [0]). setattribute ("Alt", "wide graph"); // create a tile notification object tilenotification = new tilenotification (tilexml); // to overwrite the FIFO queue behavior, you can mark the notification. If a new notification has the same tag as an existing notification, the new notification will replace the existing notification. // if there are more than five notifications in the queue, the first notification will be deleted. // The display order of the notification is not necessarily the same as that of the incoming notification. tilenotification. tag = I. tostring (); // update tile tileupdatemanager. createtileupdaterforapplication (). update (tilenotification );}}

Note:

1. We have used a loop to add multiple notifications. Before using multiple notifications, we must first enable the notification queue.

2. A maximum of five notifications can be added. The FIFO rule is followed, that is, when the number of notifications is greater than five, the notifications that first enter the queue will be deleted, however, we can also change this rule by setting the tag of the notification. When a notification with the same tag enters the queue, the notification will be replaced no matter where it is first entered, and enters the queue as a new notification. In this way, we can use queue notifications to update some stock news.

 

Summary:

The essence of a notification is an XML document. We only need to assign the relevant content system to this document to automatically update the notification for us.

 

Question ??? If you know that you must tell me

1. I wonder where I can set the refresh frequency of the tile notification Queue (because I see that the refresh frequency of other tile notifications is faster than what I created)

 

Welcome to study and grow together with Uncle bird. Uncle bird's Weibo has more features.

 

 

 

 

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.