Search code examples
c#windows-phone-8live-tile

ShellTile.Create with FlipTileData throws InvalidOperationException?


I am trying to create a tile using FlipTileData in Windows Phone 8. I use this code:

        const string mainPage = "/MainPage.xaml";

        ...

        Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
        FlipTileData tileData = new FlipTileData();
        tileData.Title = tileTitle;
        tileData.BackgroundImage = new Uri("isostore:" + isourl);
        tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
        tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
        ShellTile.Create(mp, tileData);

This throws an InvalidOperationException at the ShellTile.Create method. There are no other tiles with the same Navigation URI. What am I doing wrong here?

This code works fine using the StandardTileData class, excluding the SmallBackgroundImage and WideBackgroundImage properties.

If it matters, the full code is:

    const string mainPage = "/MainPage.xaml";

    ...

    private void createbutton_Click(object sender, RoutedEventArgs e)
    {
        string tileId = new Random().Next().ToString();
        Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
        WriteableBitmap wbmp = new WriteableBitmap(tileGrid, null);

        string isourl = "/Shared/ShellContent/" + tileId + ".jpg";
        IsolatedStorageFileStream isfs = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(isourl);
        wbmp.SaveJpeg(isfs, 173, 173, 0, 100);
        isfs.Close();

        FlipTileData tileData = new FlipTileData();
        tileData.Title = tileTitle;
        tileData.BackgroundImage = new Uri("isostore:" + isourl);
        tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
        tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
        ShellTile.Create(mp, tileData);
    }

Solution

  • If using the new tile templates you need to use the overload of ShellTile.Create() that includes a third parameter.

    This should do the trick:

    ShellTile.Create(mp, tileData, true);