In the end of 2011 we enhanced our suite with LiveTileHelper. This component can be very useful when creating Secondary tiles. It extends the StandardTileData with two additional properties: VisualElement and BackVisualElement.
Since then we have received a lot of positive feedback about the LiveTileHelper and one of the frequently asked questions was "How to update the tile periodically when some of the data changes?". It is a good question and since it describes a very common scenario we decided to show you how to do it.
To update the tile periodically, we are going to use a PeriodicTask. It inherits from ScheduledTask and ScheduledAction and allows applications to perform processing even when the main application is not in the foreground. If you are not familiar with such Background Agents, I recommend that you read the article "How to: Implement Background Agents for Windows Phone". In short, you need to add a Scheduled Task project to your solution and reference it in your foreground application project. This will create a project, which has a ScheduledAgent class and OnInvoke method inside. This is the method that will be executed every time when the Background Agent is invoked. Now inside this method you can place the logic that will update the tile. You have to use a Dispatcher, because otherwise it would cause an Invalid-cross-thread-reference, because you are trying to update the UI from another thread. You need to add a reference to the Telerik.Windows.BackgroundAgentTools assembly in order to use the LiveTileHelper from inside a BackgroundAgent. Please note that this assembly should be included only in the project that contains the background agent and the Telerik.Windows.Core assembly should be added to the foreground application.
Now, let's go back to the foreground application. We need to add the agent here and we also have to create the tile that will be updated later.
First, let's create the tile by using dynamic visual element from our application:
And then add the agent that is going to run in the background:
We use the LaunchForTest method to force the invocation of the agent for debugging purposes.
And that's all! When you start the agent, it will make sure to update the tile periodically and when you have some new information, for example from an rss feed, it will be reflected on the tile.
You can download the attached project with full source code here.
If you still don't have RadControls for WindowsPhone, you can download the free trial.
Keep using the Telerik's LiveTileHelper and share your comments and feedback in our forums.
Subscribe to be the first to get our expert-written articles and tutorials for developers!