The application we developed will be displayed in the form of a tile in the Win8 interface. The tile displays the application map, that is, the logo.png image file in the project. Developers can push text or image information to the tile according to application needs, so as to change the content displayed in the tile.
Windows. UI. configurations are the main APIs used for tile notification pushing. The API provides many tile display templates tiletemplatetype. The template structure is described in XML. What we need to do is edit the content in the template and push it to the tile. Some children's shoes may find the followingCodeTwo templates are defined: tilewideimageandtext01 and tilesquaretext04. This is because the Win8 application has two sizes of tile, so you cannot know the size of the current tile when pushing notifications. If the pushed template content is inconsistent with the tile size, the display may cause problems. Therefore, we recommend that you define all the two size templates so that no matter what size the tile is.
< Tile > < Visual > < Binding Template = "Tilewideimageandtext01"> < Image SRC = "MS-appx: // assets/wide.png"/> < Text > This is a wide tile notification! </ Text > </ Binding > < Binding Template = "Tilesquaretext04"> < Text > This is a square tile notification! </ Text > </ Binding > </ Visual > </ Tile >
Next, we need to edit the template content (the following code). First, use the gettemplatecontent method of the tileupdatemanager class to define a large size tile template. In this example, tilewideimageandtext01 is a large size template with images and text, tiletemplatetype enumeration also contains other types of templates, which can be selected by developers. You can use the <text> and <image> labels of the standard BOM editing template to set values and attributes.
Similarly, after editing the small size tile, load it to the large size template <visual> (such as XML ). Use tilenotification to create a tile notification. You can use expirationtime to set the time when the tile notification disappears. Finally, use tileupdatemanager. createtileupdaterforapplication (). Update () to push notifications. You can use clear () to clear tile notifications.
// For wide Tile Xmldocument Widetile = Tileupdatemanager . Gettemplatecontent ( Tiletemplatetype . Tilewideimageandtext01 ); Xmlnodelist Wdtxtattribute = widetile. getelementsbytagname ( "Text" ); Xmlnodelist Wdimgattribute = widetile. getelementsbytagname ( "Image" );(( Xmlelement ) Wdimgattribute [0]). setattribute ( "Src" , "Ms-appx: // assets/wide.png" ); Wdtxtattribute [0]. innertext = "This is a wide tile notification! " ; // For square Tile Xmldocument Sqtile = Tileupdatemanager . Gettemplatecontent ( Tiletemplatetype . Tilesquaretext04 ); Xmlnodelist Sqtxtattribute = sqtile. getelementsbytagname ( "Text" ); Sqtxtattribute [0]. innertext = "This is a square tile notification! " ; Ixmlnode Node = widetile. importnode (sqtile. getelementsbytagname ( "Binding" ). Item (0 ), True ); Widetile. getelementsbytagname ( "Visual" ). Item (0). appendchild (node ); Tilenotification Tilenotification = New Tilenotification (Widetile); tilenotification. expirationtime = Datetimeoffset . Utcnow. addseconds (10 ); Tileupdatemanager . Createtileupdaterforapplication (). Update (tilenotification );
Illustration
Source code download
Http://sdrv.ms/WhVSLU