1

I'm trying to create and update a tile for my windows phone application. But when I try to implement code below (which is works good for msdn sample), it throws "An exception of type 'System.ArgumentException' occurred in Microsoft.Phone.ni.dll but was not handled in user code

Additional information: Template type mismatch. You can only update the tile using the same template it was created with."

int newCount = 0;

        // Application Tile is always the first Tile, even if it is not pinned to Start.
        ShellTile TileToFind = ShellTile.ActiveTiles.First();

        // Application should always be found
        if (TileToFind != null)
        {
            // if Count was not entered, then assume a value of 0
            if (textBoxCount.Text == "")
            {
                // A value of '0' means do not display the Count.
                newCount = 0;
            }
            // otherwise get the numerical value for Count
            else
            {
                newCount = int.Parse(textBoxCount.Text);
            }

            // set the properties to update for the Application Tile
            // Empty strings for the text values and URIs will result in the property being cleared.
            StandardTileData NewTileData = new StandardTileData
            {
                Title = textBoxTitle.Text,
                BackgroundImage = new Uri(textBoxBackgroundImage.Text, UriKind.Relative),
                Count = newCount,
                BackTitle = textBoxBackTitle.Text,
                BackBackgroundImage = new Uri(textBoxBackBackgroundImage.Text, UriKind.Relative),
                BackContent = textBoxBackContent.Text
            };

            // Update the Application Tile
            TileToFind.Update(NewTileData);
        }

Exception is thrown by "TileToFind.Update(NewTileData);" line. I'm waiting for your suggestions. Thank you.

T3sTR
  • 71
  • 8
  • Is your app target WP8.1, WP8 or Wp7? – Chris Shao May 27 '14 at 09:45
  • As I know, Windows Phone 8.1 can't use ShellTile in Microsoft.Phone.Shell namespace. If your app is target WP8, you should create and update tile with the same way. For example, if you create tile with FlipTileData, you should update it with FlipTileData. – Chris Shao May 27 '14 at 09:54
  • It should be WP8 then. When I installed WP8.1 SDK it changed by visual studio I think. Well how can I learn which type of tile exist for update? Because of ShellTile.ActiveTiles returns ShellTile it always throws exception to all tile types. How can I implement it? Thank you by the way. – T3sTR May 27 '14 at 10:01
  • read my answer please. – Chris Shao May 27 '14 at 10:06

1 Answers1

1

In Windows Phone 8, You can look at the WMAppManifest.xml in your project. Tile Template can be TemplateFlip, TemplateCycle or TemplateIconic. Their Tile Data are:

FlipTileData(TemplateFlip), CycleTileData(TemplateCycle) and IconicTileData(TemplateIconic). Choose right TileData by the type of Tile Template in your WMAppManifest.xml.

Chris Shao
  • 8,231
  • 3
  • 39
  • 37
  • I will try it, thank you. I will mark as answer when it is ok. – T3sTR May 27 '14 at 10:15
  • My mistake! I changed it to TemplateIconic but when it threw exception I thought it's about ShellTile and FlipTileData but it wasn't. Thank you again. And can I ask a question? How can I change my project to WP8.1, What I need to do it? Thank you again. – T3sTR May 27 '14 at 10:54
  • You are welcome. If you want to target to WP8.1, just right click on project, and you will find it. – Chris Shao May 28 '14 at 00:54