Click here to Skip to main content
13,140,591 members (48,115 online)
Click here to Skip to main content

Stats

5K views
Posted 11 Sep 2012

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

, 11 Sep 2012
This sample demonstrates how to use the Tile Template, specifically the TileSquareImage and an image.
LiveTileFun
Assets
AfterTileNotification.png
AnimeRunner150.png
AnimeRunner24BadgeSize.png
AnimeRunner30.png
AnimeRunner310.png
Logo.png
redWide.png
redWide.scale-100.png
redWide.scale-140.png
SmallLogo.png
SplashScreen.png
StoreLogo.png
Winner150.png
Common
LiveTileFun.vcxproj.filters
LiveTileFun.vcxproj.user
LiveTileFun_TemporaryKey.pfx
Package.appxmanifest
#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)

Share

About the Author

sam stokes
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.

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 12 Sep 2012
Article Copyright 2012 by sam stokes
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid