Working with Live Tiles locally using XAML and C++ / CX using Images

In parallel to Daniel Egan’s excellent post on working with Live Tile Locally, I decided to glom on to his writing and parallel his message but use XAML and C++.  The form has the following elements:


About mid way down in Daniel’s referenced blog he shows you a simple form and two buttons. I use a slightly different XAML form but the result is same with respect to the Live Tile Notification.

The code can be found at:



Under the click event for the change tile button, we will use the same basic code from yesterday, with a minor change, the TileTemplateType has been changed to TileSquareImage and the GetElementsByTagName has been changed to “image”  As expected this is because we are using the Square or 150X150 pixel image.


There is a major change has been an addition of the line that:

                                SetAttribute("src", "ms-appx:///Assets/Winner150.png");

The dynamic_cast, unlike the static_cast are safer as the dynamic_cast to an ambiguous pointer will fail, the static_cast will returns nothing or cause a soft failure that isn’t detected, except as a bad user experience.  Dynamic_casts only work on pointers or references with the runtime overhead cost.

See code below…

void LiveTileFun::MainPage::DemoTile1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    //This line can remain the same, except for the template, 
    //in this case TileSquareImage
    //If you use the wrong template, then an error is thrown
    XmlDocument^ tileXml = 
    // This line changes, now you look for the default tag 
    // of image, tileImageAttribute is
    // a variable that I created or took from an example, 
    // it is not a keyword
    XmlNodeList^ tileImageAttributes = 
    // the static_cast or a dynamic_cast is used to move 
    // the image in to the element Item 0 or the first item
    // in this case, you only get a single item, so you must 
    // use item 0, otherwise you get an error
                        SetAttribute("src", "ms-appx:///Assets/Winner150.png"); 
    // Send your tile notificaiton and then update it, 
    // this code did not change it would change if you 
    // modify the XmlDocument variable titleXml
    TileNotification^ tileNotification = 
        ref new TileNotification(tileXml);




















The code can be found at:

Comments (0)

Skip to main content