简体   繁体   English

无法更新动态创建的实时图块

[英]Can't update dynamically created live tile

I am developing a shopping app for windows phone. 我正在开发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: 如果您像这样更新UpdateTile()方法:

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

the tile which was created via code will be updated. 通过代码创建的图块将被更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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