Click here to Skip to main content
15,881,424 members
Articles / Desktop Programming / Win32

Super Simple Live Tile Notification Using an Image (C++)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Sep 2012Ms-PL 7.2K  
This sample demonstrates how to use the Tile Template, specifically the TileSquareImage and an image.
#include "pch.h"
#include "MainPage.xaml.h"

using namespace LiveTileFun;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Navigation;
//*******************************************************
//Add the next two lines 
//*******************************************************
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;
//*******************************************************
//*******************************************************

MainPage::MainPage()
{
	InitializeComponent();
}

void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
	(void) e;	// Unused parameter
}

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 = 
				TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquareImage);
	//*************************************************************************************
	// 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 = tileXml->GetElementsByTagName("image");
	//*************************************************************************************
	// 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
	dynamic_cast<XmlElement^>(tileImageAttributes->Item(0))->
								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);
	TileUpdateManager::CreateTileUpdaterForApplication()->Update(tileNotification);
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Instructor / Trainer Microsoft
United States United States
Sam Stokes works for Microsoft as a technology evangelist and is focused on working with colleges, students and professors.

Comments and Discussions