0

I am trying to use the Iconic Tile Template to create a secondary live tile in my Windows Phone 8 app and I am getting an exception when creating the tile. The exception I am getting is:

A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.ni.dll

Additional information: initialData can be only of type StandardTileData.

the method I use to create the live tile is:

public void PinLock(Lock item)
{
    Uri smallIcon = new Uri(item.IsLocked ? LockedIcon : UnlockedIcon, UriKind.Relative);
    Uri largeIcon = new Uri(item.IsLocked ? LockedIcon : UnlockedIcon, UriKind.Relative);

    var tileData = new IconicTileData
    {
        IconImage = largeIcon,
        SmallIconImage = smallIcon,
        Title = item.Name
    };
    string tileUri = "/MainPage.xaml?Action=LockDetails&LockId=" + item.Id;
    ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData);
}

I have the live tile type set up in the WMAppManifest.xml like this:

<PrimaryToken TokenID="MyToken" TaskName="_default">
<TemplateIconic>
    <SmallImageURI IsRelative="true" IsResource="false">Assets\lock-icon.png</SmallImageURI>
    <Count>0</Count>
    <IconImageURI IsRelative="true" IsResource="false">Assets\lock-icon.png</IconImageURI>
    <Title>Locky</Title>
    <Message>
    </Message>
    <BackgroundColor>
    </BackgroundColor>
    <HasLarge>false</HasLarge>
    <LargeContent1>
    </LargeContent1>
    <LargeContent2>
    </LargeContent2>
    <LargeContent3>
    </LargeContent3>
    <DeviceLockImageURI IsRelative="true" IsResource="false">
    </DeviceLockImageURI>
</TemplateIconic>
</PrimaryToken>
</Tokens>

I can't find any good examples of the correct way to do this and I can't find anybody else on the internet running into this exception message.

Other things I have tried:

  • First creating the secondary template using StandardTemplateTileData and then when I update it try using IconicTileData. This throws an exception.
  • First creating the secondary template using StandardTemplateTileData and then deleting it and replacing it with one using IconicTileData. This didn't work (throws the same exception as above)

Any help or good examples would be very much appreciated.

Luke Foust
  • 2,234
  • 5
  • 29
  • 36

1 Answers1

1

The answer is in your exception. When creating additional tiles on the start screen, only a class which derives from StandardTileData can be used. This limits you to that class or its one derived implementation, FlipTileData. IconicTileData and CycleTileData derive from the lower level ShellTitleData. This class is also the base for StandardTileData.

Some examples of creating FlipTileData can be found on the MSDN documentation, but as it derives from the same base class as your example above, you might be able to get away with simply changing the class name and patching up your XML a tiny bit.

lsuarez
  • 4,952
  • 1
  • 29
  • 51
  • I am using IconicTileData (see my code example above) but I am still getting this exception. If I wasn't using a class which derives from ShellTileData then I think I would be getting a compile time exception ;) – Luke Foust Nov 25 '13 at 06:26
  • You aren't reading very carefully. For one, compile time and run time are two different beasts. ShellTile.Create is likely also used by your application on install to create its application tile. However, for pinning tiles to the start screen during application runtime, the code likely has a restriction that your tile must derive from StandardTileData, not ShellTileData, which is exactly what your exception states. – lsuarez Nov 25 '13 at 06:35
  • Ok, so now I see your point. The Iconic Tile template is only for your apps main tile and not for secondary tiles. Thank you for clarifying that. The documentation and API definitely don't make that clear. Although once you know that the exception error message makes much more sense ;) – Luke Foust Nov 25 '13 at 06:43
  • @LukeFoust One thing upon reading a little further. It seems you also have the option of using StandardTileData directly rather than the flip derived class. It is not an abstract implementation. – lsuarez Nov 25 '13 at 06:44