Continuing my series based on the presentations I’m giving on Europe, today I return to Tiles to look at creating Secondary tiles.
A secondary tile can be created by the user and pinned to the start menu to provide deep access into your program. A classic example of a secondary tile would be to pin a tile for your home town in a weather application, or a specific stock in a portfolio program.
I’ve stripped down the Microsoft SDK sample to its essentials to make it a bit easier to see how to create a secondary tile.
On the home page add this XAML:
This will create a TextBlock to provide an update message and a button to create the tile.
You will need to create two tile images (or download the source for this project) and place them in your assets folder. One is for the wide tile, the other for the square.
We begin the event handler by getting the URL of the two images,
You can pass ActivationArguments to your tile, which you get back upon activation to tell you which tile was clicked and where in your program to go. We’ll create a string for the ActivationArguments,
The constant dynamicTileID is declared at the top of the file, but could be retrieved from a database, etc.
We’re ready to create the Secondary tile,
The arguments are:
You can now set properties on the secondary tile such as the foreground text color,
You are ready to instantiate the tile and pin it to the start menu. You do so by calling RequestCreateForSelectionAsync on the secondary tile, passing in the location you want to place the flyout,
Note that GetElementRect is a simple helper method that returns a rect given a Framework element.
Assuming the return value is true, you have successfully pinned your secondary tile,
Download the source code here
Jesse Liberty has three decades of experience writing and delivering software projects. He is the author of 2 dozen books and has been a Distinguished Software Engineer for AT&T and a VP for Information Services for Citibank and a Software Architect for PBS. You can read more on his personal blog or follow him on twitter
Subscribe to be the first to get our expert-written articles and tutorials for developers!