更新Windows Phone 7中的Live Tile无法正常工作

时间:2013-04-23 20:57:30

标签: c# windows-phone-7 live-tile

我在更新从用户控件(LiveTiles.Example)创建的Windows Phone 7中的辅助动态磁贴时遇到问题。

这是一个包含在库中的辅助类。应该从主应用程序中的方法(活动时)或计划任务中调用它。

“创建”方法工作得很好。但“更新”方法根本无效。

任何人都可以暗示我做错了什么?

感谢很多!!!

using Microsoft.Phone.Shell;
using Ree7.TileToolkit;
using System;
using System.Linq;
using System.Windows;

namespace LiveTiles
{
    public class ExampleHelper
    {
        public static void Create(Entities.Example.ExampleList selectedExample, Entities.MyVal[] MyVals)
        {
            StandardTileData tileData = ExampleTileDataCreate(selectedExample, MyVals);
            ShellTile.Create(new Uri(string.Format("/MainPage.xaml?Example={0}", selectedExample), UriKind.Relative), tileData);
        }

        public static StandardTileData ExampleTileDataCreate(Entities.Example.ExampleList selectedExample, Entities.MyVal[] MyVals)
        {
            StandardTileData standardTileData = new StandardTileData();

            var ExampleTile = new LiveTiles.Example();
            ExampleTile.Update(MyVals, selectedExample);
            var customTile = CustomTileFactory.GetTemplatedTile("Example" + selectedExample, ExampleTile, TileSize.Standard);
            customTile.UpdateLayout();
            standardTileData = customTile.GetShellTileData();

            return standardTileData;
        }

        public static void Update(Entities.Example.ExampleList selectedExample, Entities.MyVal[] MyVals)
        {
            StandardTileData tileData;
            tileData = ExampleTileDataUpdate(selectedExample, MyVals);

            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(string.Format("Example={0}", selectedExample)));
            var i = ShellTile.ActiveTiles.Count(x => x.NavigationUri.ToString().Contains(string.Format("Example={0}", selectedExample)));
            tile.Update(tileData);
        }

        public static StandardTileData ExampleTileDataUpdate(Entities.Example.ExampleList selectedExample, Entities.MyVal[] MyVals)
        {
            StandardTileData standardTileData = new StandardTileData();

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var ExampleTile = new LiveTiles.Example();
                ExampleTile.Update(MyVals, selectedExample);
                var customTile = CustomTileFactory.GetTemplatedTile("Example" + selectedExample, ExampleTile, TileSize.Standard);
                customTile.UpdateLayout();
                standardTileData = customTile.GetShellTileData();
            });
            return standardTileData;
        }
    }
}

0 个答案:

没有答案