SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Windows Phone Application Development Tutorials, Articles and Resources for Mobile App Programmers

ShellTile.Update Template type mismatch Exception

Windows Phone 8 app developers can create secondary tiles programmatically within their Windows Phone app codes. It is also possible to update these Windows Phone 8 app tiles too. Unfortunately developers can only update tiles with the same type of tile which also has an exception as I experienced.

Let's talk on a sample case with sample code just like a tutorial. To update a tile, developers can use a similar C# code as shown below in their Windows Phone apps.

// Get tile data
ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(o => o.NavigationUri.ToString().Contains("/MainPage.xaml"));

// Create new tile and set properties
List<Uri> imageList = new List<Uri>();
Uri uri = new Uri(imageURL, UriKind.Relative);

FlipTileData tiledata = new FlipTileData();
tiledata.Title = "App title";
tiledata.BackTitle = "App Tile Back title";
tiledata.BackContent = "App tile back content";
tiledata.Count = null;
tiledata.BackBackgroundImage = imageList[0];
tiledata.BackgroundImage = imageList[0];

// Update ShellTile with new tile data

But it is also possible to get "Template type mismatch" exception at ShellTile.Update() method. This error occurs when you update a tile with an other type of tile.

{System.ArgumentException: Template type mismatch. You can only update the tile using the same template it was created with.
 at Microsoft.Phone.Shell.ShellTile.Update(ShellTileData data)
 at wp8app.MainPage.setTile(String imageURL, Boolean all)
 at wp8app.MainPage.Image_Tap(Object sender, GestureEventArgs e)
 at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
 at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}

update tiles programmatically for Windows Phone 8 apps

For example, assume that you create CycleTile for Windows Phone 8 app at first. If you try to update CycleTile with a FlipTile, then your Windows Phone 8 app code will throw an exception at ShellTile.Update() method. The exception message is describing the cause briefly: "You can only update the tile using the same template it was created with"

But it is also interesting that if you have a FlipTileData, you can update it with a CycleTileData object. So I assume that there is a hierarchy between tile templates which is not very clear.

Although I tried to find a method to test and get the existing tile template type, but I could not find a build-in method or function. What I could only do to overcome this exception is to use TRY - CATCH method and within the CATCH block I deleted the existing tile and created a new tile instead of update task.

 ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), tiledata, false);

I hope this code sample helps you if you have also experienced a similar problem.

Windows 10 Games

Microsoft Games on Windows 8 and Windows 10

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.