Saturday, 29 March 2014

Implementing live tiles on windows

Lets do it now!
1. Open visual studio 13 > New project > Visual C# > Blank App
2. In solution explorer, open MainPage.Xaml and add a button.
3. Add below lines of code to button event(right clicking button code and select view definition) in csharp file.
string tileXmlString = " <tile >"
                + " <visual version='2' >"
                + " <binding template='TileSquare150x150Image' fallback='TileSquareImage' >"
                + " <image id='1' src='ms-appx:///images/graySquare150x150.png' alt='Gray image'/ >"
                + " </binding >"
                + " <binding template='TileWide310x150ImageAndText01' fallback='TileWideImageAndText01' >"
                + " <image id='1' src='ms-appx:///images/New Tile.png' alt='Green'/ >"
                + " <text id='1' >Microsoft Innovation Center </text >"
                + " </binding >"
                + " <binding template='TileSquare310x310Image' >"
                + " <image id='1' src='ms-appx:///images/purpleSquare310x310.png' alt='Purple image'/ >"
                + " </binding >"
                + " </visual >"
                + " </tile >";

            // Create a DOM.
            Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument();

            // Load the xml string into the DOM.
            tileDOM.LoadXml(tileXmlString);

            // Create a tile notification.
            TileNotification tile = new TileNotification(tileDOM);

            // Send the notification to the application’s tile.
            TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);

No comments:

Post a Comment