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:
- A string representing the ID
- A string representing the short name
- A string representing the display name
- A string for the ActivationArguments
- TileOptions (an enumerated constant)
- The URI for the logo for the square tile
- The URI for the logo for the wide tile
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