9

I'm creating a live tile on the device with the following code:

ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
StandardTileData newTileData = new StandardTileData
{
    BackgroundImage = new Uri(string.Format("isostore:{0}", DefaultLiveTilePath), UriKind.Absolute),
    Title = "Test"
};
tile.Update(newTileData);

At a later point I would like to delete the live tile image and have it revert to the app icon when pinned. Is this possible?

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
James Cadd
  • 12,136
  • 30
  • 85
  • 134
  • Can't you just use the same code to restore the original image? After all, the original is packaged with your app. – Praetorian Sep 09 '11 at 20:56
  • Yes, but the problem is I'm also using the Back image and content of the tile. When I restore the original image I don't want it to flip over. Setting the back content and backbackgroundimage to null doesn't do the trick either so I thought it would be best to see if there's a way to delete my tile altogether. – James Cadd Sep 09 '11 at 20:58
  • 5
    Does http://stackoverflow.com/questions/6573806/mango-application-tile-remove-back do not the trick? – Ralf Ehlert Sep 09 '11 at 21:14
  • 1
    Since you can't remove a Tile from code, Ralf Ehlert's answer is the way to do it. Ralf should add his comment as a answer to this question. – Claus Jørgensen Sep 10 '11 at 13:40

3 Answers3

6

According to this blog you shoudl use this code

public void DeleteExistingTile()  
{  
    var foundTile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("DetailId=123"));  

    // If the Tile was found, then delete it.  
    if (foundTile != null)  
    {  
        foundTile.Delete();  
    }  
}  
Mattias Cibien
  • 296
  • 2
  • 16
3

I'm using the following code when resetting my tile back to normal everytime the app starts:

    private void ResetLiveTileToNormal()
    {
        ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault();


        ShellTileData shellData = new StandardTileData
        {
            Title = "XXXXXXXX",
            Count = 0,
            BackContent = "",
            BackTitle = "",
            BackBackgroundImage = new Uri("", UriKind.Relative),
            BackgroundImage = new Uri(@"/Images/LiveTiles/XXXXXX.png", UriKind.Relative)
        };
        TileToFind.Update(shellData);
    }
robertk
  • 2,461
  • 1
  • 27
  • 39
2

ShellTile.ActiveTiles.FirstOrDefault(); is obsolete.

void clearTile() {

            ShellTileData tileData = new StandardTileData
            {
                Title = "",
                Count = 0,
                BackContent = "",
                BackTitle = "",
                BackBackgroundImage = new Uri("", UriKind.Relative),
                BackgroundImage = new Uri(@"/ApplicationIcon.png", UriKind.Relative)
            };
            IEnumerator<ShellTile> it = ShellTile.ActiveTiles.GetEnumerator();
            it.MoveNext();
            ShellTile tile = it.Current;
            tile.Update(tileData);
        }

Based on research and thanks to robertftw

jonsca
  • 10,218
  • 26
  • 54
  • 62