WP7 Mango: How do I delete a live tile?
Asked Answered
O

3

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?

Olinger answered 9/9, 2011 at 20:30 Comment(4)
Can't you just use the same code to restore the original image? After all, the original is packaged with your app.Suzannesuzerain
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.Olinger
Does #6574306 do not the trick?Zahavi
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.Deuteragonist
A
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();  
    }  
}  
Anglofrench answered 23/9, 2011 at 16:36 Comment(2)
That code shows how to delete a secondary tile not how to reset the app's primary tile.Bacchius
Sorry, misunderstood the question.Anglofrench
C
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);
    }
Cambyses answered 24/9, 2011 at 16:39 Comment(0)
R
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

Rawhide answered 12/9, 2012 at 5:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.