Question

I am developing a shopping app for windows phone.

If I pin the tile manually i can update the tile by my code .

Here my code to update the tile

 ShellTile TileToFind = ShellTile.ActiveTiles.First();

            StandardTileData NewTileData = new StandardTileData
            {
                BackgroundImage = new Uri(offer_mobile_image[0], UriKind.RelativeOrAbsolute),
                Count = NotificationCount,
                BackTitle = location_area,
                BackContent = offer_title,
            };


            TileToFind.Update(NewTileData);

If i create my live tile dynamically by code , I can't update my tile

Here the code which i used to create live tile

private void PinToStart()
    {
        StandardTileData standardTileData = new StandardTileData();
        standardTileData.BackgroundImage = new Uri(@"/ApplicationTile.png", UriKind.RelativeOrAbsolute);
        standardTileData.Title = "MyApplication";
        standardTileData.BackTitle = "this is my app";
        standardTileData.BackContent = "this is very good app";

        // Check if the application tile has already been defined - this is a tile that links to the app main page
        ShellTile tiletopin = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("MainPage.xaml"));
        if (tiletopin == null)
        {
            //Create ShellTile linking to main page of app
            ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), standardTileData);
        }
        else
        {
            MessageBox.Show("Application is already Pinned");
        }
    }

Can anybody help me to update dynamically created tile. Thank you.

Was it helpful?

Solution

Your problem is - you are trying to update primary tile, but you create a secondary tile. Primary tile is always the first one.

If you update your UpdateTile() method like this:

ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(
              x => x.NavigationUri.ToString().Contains("MainPage.xaml"));

the tile which was created via code will be updated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top