Dynamic and secondary magnetic stickers for Windows 8 Development)

Source: Internet
Author: User

The tile is an application in the system's Start Menu. Dynamic tile displays new, important, and customized content to users. Tile notification is a fixed format of XML, which contains text and image content. In the Application List, a square logo must be included. If the application wants to use a wide template logo, you must also specify it in the list. If your application also supports width tile, we strongly recommend that you pre-load the square and width in the pre-loaded XML, therefore, you can receive notifications whether the tile in the Start menu is square or wide.

The following is a tile template provided by Microsoft:

Tile and tile notification: http://msdn.microsoft.com/zh-cn/library/windows/apps/hh779724.aspx

Tile template Directory: http://msdn.microsoft.com/zh-cn/library/windows/apps/hh761491.aspx

1. Dynamic Tile

Use the tileupdatemanager class in the windows. UI. configurications namespace to create a tileupdater object used to change and update the Startup Menu block. This class provides access to the XML content of the tile template provided by the system, so that you can customize it to update your tile content. The XML content of a specific template can be modified based on the Microsoft template.

Public static class tileupdatemanager {// Abstract: // create and initialize a new instance of tileupdater. This operation allows you to change the appearance of the calling application graph block. //// Return result: // The tiled object that sends changes to the application. [Overload ("createtileupdaterforapplication")] public static tileupdater createtileupdaterforapplication (); // Abstract: // create and initialize a new instance of tileupdater in the graph block, the graph block belongs to another application in the same package as the calling application. Tileupdater allows developers to change the tile appearance. //// Parameter: // applicationid: // unique ID of the title. //// Return result: // used to send the change to the tile ID object through applicationid. [Overload ("createtileupdaterforapplicationwithid")] public static tileupdater createtileupdaterforapplication (string applicationid); // Abstract: // create and initialize a new tileupdater instance, this operation allows you to change the appearance of the secondary tile. Tile can belong to the calling application or any other application in the same package. //// Parameter: // tileid: // unique ID of the title. //// Return result: // used to send updates to objects with tiled IDs. Public static tileupdater createtileupdaterforsecondarytile (string tileid); // Abstract: // obtain the XML content of one of the predefined graph block templates, in this way, you can customize the content to update the image block. //// Parameter: // type: // Template Name. //// Return result: // The object containing XML. Public static xmldocument gettemplatecontent (tiletemplatetype type );}

  

// Void updatetilebutton_click (Object sender, routedeventargs E) {string tilexmlstring = "<tile>" + "<visual>" + "<binding template = 'tilewideimageandtext01 '>" + "<text id = '1'> This tile notification uses MS-appx images </text> "+" <image id = '1' src = 'Ms-appx: /// images/redwide.png 'alt = 'Red image'/> "+" </binding> "+" <binding template = 'tilesquareimag'> "+" <image id = '1' src = 'Ms-appx: /// images/graysquare.png 'alt = 'Gray image'/> "+" </binding> "+" </visual> "+" </tile> "; windows. data. XML. dom. xmldocument tiledom = new windows. data. XML. dom. xmldocument (); tiledom. loadxml (tilexmlstring); tilenotification tile = new tilenotification (tiledom); tileupdatemanager. createtileupdaterforapplication (). update (tile );}

 

In addition, we can download the icationicationsextensions file, reference the file to our project, and use the classes and methods provided in the file to create our dynamic tile, this is different from the previous one. Instead of using an XML template to set a tile template, we can assign values to the attributes of the template class through a specific template class to implement dynamic tile. The following code implements the switching between the last five dynamic tiles. The template displays the following style:

Wide tile: The left side is a small image, and the right side is the title string of the large text on the first line. The following is a string of four lines of general text. Text does not wrap automatically.

Narrow tile: The title string of a large text. Below is a string that can contain up to three lines of regular text.

Private void updatetiletext (string key, string [] array) // The array has four elements, each displaying four rows of Data {try {If (array! = NULL & array. length> 1) {// create a square tile template. itilesquaretext02 is a large text title string. Below is a string that can contain up to three lines of regular text. Itilesquaretext02 squarecontent = tilecontentfactory. createtilesquaretext02 (); squarecontent. textheading. TEXT = key; squarecontent. textbodywrap. TEXT = array [0]; // create a wide template. The left side of itilewidesmallimageandtext02 is a small image, and the right side is the title string of the large text on the first line, the following is a string of four lines of general text. Text does not wrap automatically. Itilewidesmallimageandtext02 tilecontent = tilecontentfactory. createtilewidesmallimageandtext02 (); tilecontent. image. src = "MS-appx: // assets/logo.png"; tilecontent. textheading. TEXT = word; For (INT I = 0; I <array. length; I ++) {Switch (I) {Case 0: tilecontent. textbody1.text = array [I]; // The first line of Data break; Case 1: tilecontent. textbody2.text = array [I]; // The second line of Data break; Case 2: tilecontent. textbody3.text = array [I]; // The third line of Data break; Case 3: tilecontent. textbody4.text = array [I]; // The fourth line of Data break;} tilecontent. squarecontent = squarecontent; tileupdatemanager. createtileupdaterforapplication (). update (tilecontent. createnotification (); tileupdatemanager. createtileupdaterforapplication (). enablenotifquequeue (true) ;}} catch {}}


Note: The dynamic tile effect must be displayed on the physical machine and cannot be displayed in the simulator.

2. Secondary Tile)

The secondary tile enables users to send specific content and deep links of the Windows App Store app-to a reference to a specific location inside the app-to the Start Screen. The secondary tile enables users to customize the "Start" screen experience by using friends, news sources, stock quotes, and other content that is important to them. The option for creating a secondary tile is most often displayed in the UI as the "attach to Start Menu" option. The fixed content is to create a secondary tile for it. This option is often displayed as a flag on the application bar. By touching or clicking a secondary tile, it starts to the parent application to highlight an experience centered on fixed content or contacts.Only the user can fix the secondary tile. The application cannot fix the secondary tile programmatically without the user's permission. You can also use the "Start" screen or parent application to explicitly Delete the secondary tile.

 1) before attaching a fixed secondary tile, the user must confirm that the pop-up window for confirmation should be displayed next to the button for calling the fixed request.

public Rect GetElementRect(FrameworkElement element)  {     GeneralTransform buttonTransform = element.TransformToVisual(null);     Point point = buttonTransform.TransformPoint(new Point());     return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));   } 

2) Add a secondary tile. First, you must set the ID of the secondary tile.

Public const string appbartileid = "secondarytile. AppBar ";

 

Private async void addbuttonclicked (Object sender, routedeventargs e) {// when you select a button on the application bar, a pop-up window asking you to confirm is displayed. // To ensure that the application bar is not canceled when the pop-up window is displayed, you must set the issticky attribute of the application bar. This. bottomappbar. issticky = true; If (secondarytile. exists (appbartileid) {// cancel the secondary tile secondarytile = new secondarytile (appbartileid); bool isunpinned = await secondarytile. requestdeleteforselectionasync (getelementrect (frameworkelement) sender), windows. UI. popups. placement. above); toggleappbarbutton (isunpinned);} Some attributes of the else {// secondary tile must be set before the secondary tile can be fixed. // • unique ID of the tile. // • short name // • display name // • tile options // • Logo image // • The parameter string URI logo = new uri ("MS-appx: /// assets/logo.jpg "); string tileactivationarguments = appbartileid +" was pinned at "+ datetime. now. tolocaltime (). tostring (); secondarytile = new secondarytile (appbartileid, "secondary tile pinned via AppBar", "SDK sample secondary tile pinned from AppBar", tileactivationarguments, tileoptions. shownameonlogo, logo); // specifies Specifies the foreground text color and small logo. Secondarytile. foregroundtext = foregroundtext. Dark; secondarytile. smalllogo = new uri ("MS-appx: // assets/small.jpg"); // call the Asynchronous Method to fix the secondary tile. // In fact, this method is not to direct the tile to the "Start" screen, but to display a confirmation prompt box asking the user to allow this. Bool ispinned = await secondarytile. requestcreateforselectionasync (getelementrect (frameworkelement) sender), Windows. UI. popups. Placement. above); toggleappbarbutton (! Ispinned);} This. bottomappbar. issticky = false ;}

The above is done, and the secondary tile is added and displayed.

 

 

 

 

 

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.