我在更新从用户控件(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;
}
}
}