UWP WINDOWS10 Developing update tiles and dynamic update tiles

Source: Internet
Author: User

Original: UWP WINDOWS10 developing update tiles and dynamic update tiles

Here are two ways to update your app's tile in WINDOWS10 UWP development:

In fact, the Windows tile is implemented in XML, you just need to create the appropriate format of XML to implement the live tile

One, manually update the tile

Second, poll the update tile

"First Way" manual update of Tiles

    1. Create a text box and a button that will display the text of the text box when the button is clicked
    2. To bind a button to an event, the code is as follows
Private voidChangeBtn_Click (Objectsender, RoutedEventArgs e) {            //Get Template            varTilexml =tileupdatemanager.gettemplatecontent (tiletemplatetype.tilesquare150x150text01); //gets the element value with the label name text            varTileattributes = Tilexml.getelementsbytagname ("text"); //appends the obtained element value to a valuetileattributes[0].            AppendChild (Tilexml.createtextnode (Titlebox.text)); //Create a tile class that fills the XML data into a tile            varTilenotification =Newtilenotification (Tilexml); //Update to Tiletileupdatemanager.createtileupdaterforapplication ().        Update (tilenotification); }

This way, when the button is clicked, the app tile displays the value entered by the text box

"Second Way" poll update tile

    1. First you have to have a server, or you can parse third-party data into the tile XML format before polling
    2. The following describes using MVC as the server side, and then the UWP gets the data once every half hour to the server

If you don't understand MVC you can skip this step and see how to get the data over the network below

    1. Create an MVC Project
    2. Add a Hello Controller

and add the following data to the controller's index default method:

 Public actionresult Index ()        {            " terrorist attacks in Paris ";             " hundreds of killed. " ;             " News " ;             return View ();        }

Then add the index view in the Hello view, remove the Layout page template page, and then create a new. cshtml file, and finally you will replace all the HTML data in the index.cshtml with the following document structure

<Tile>    <Visualversion= "2">        <bindingTemplate= "tilesquare150x150text01"fallback= "TileSquareText01">            <textID= "1">@ViewBag. Title</text>            <textID= "2">@ViewBag. Content</text>            <textID= "3">@ViewBag. Type</text>            <textID= "4">@DateTime. Now.tolongtimestring ()</text>        </binding>    </Visual></Tile>

I'll introduce you to the template later.

In the final step, go back to the UWP project and create a button (when you press this button, the tile will automatically poll for updates as you set the time), add a Click event event, and add the following code:

Private voidAutoupdate_click (Objectsender, RoutedEventArgs e) {            //set a URI type variable to hold the server's XML address            varTilecontent =NewUri ("Http://localhost:61341/UWP/Index"); //Set the polling time variable to half an hour, or you can set another time            varRequestedinterval =Periodicupdaterecurrence.halfhour; //To create an instance of a tile update            varUpdater =tileupdatemanager.createtileupdaterforapplication (); //start polling for updates, incoming server tile XML file address and polling timeUpdater.        Startperiodicupdate (Tilecontent, requestedinterval); }

This allows your app to have automatic tile updates.

Let's discuss the tile template problem:

    1. Different tile sizes have different formats and you want to set different templates for each tile at the same time
    2. Templates have fixed format and different resource types, you can refer to:https://msdn.microsoft.com/zh-cn/library/windows/apps/br212859.aspx
    3. Thank you!

UWP WINDOWS10 Developing update tiles and dynamic update tiles

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.