简体   繁体   中英

Can't update dynamically created live tile

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM