James Cadd
James Cadd

Reputation: 12216

WP7 Mango: How do I delete a live tile?

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?

Upvotes: 9

Views: 1966

Answers (3)

john o. morales
john o. morales

Reputation: 21

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

Upvotes: 2

robertk
robertk

Reputation: 2461

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);
    }

Upvotes: 3

Mattias Cibien
Mattias Cibien

Reputation: 296

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();  
    }  
}  

Upvotes: 6

Related Questions