说,我想定期更新windows 8 live tile,比如说10秒后。有没有办法实现这一目标?我在windows 8中使用metro xaml c#。
这是我在Dispatcher Timer的Tick事件上编写的代码:
switch(imageIndex)
{
case 0:
imageUrl = "Assets/Image1.png";
break;
case 1:
imageUrl = "Assets/Image1.png";
break;
case 2:
imageUrl = "Assets/Image1.png";
break;
}
ITileWIdeImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01();
tileContent.TextCaptionWrap.Text = "Hello";
tileContent.Image.Src = imageUrl;
tileContent.Image.Alt = "";
ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage();
squareContent.Image.Src = imageUrl;
squareContent.Image.Alt = "";
tileContent.SquareContent = squareContent;
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());
提前致谢。
答案 0 :(得分:0)
不要使用Dispatcher Timer,因为它会降低您的应用程序速度。您可以在页面初始化程序中使用以下内容:
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
答案 1 :(得分:0)
这是你应该怎么做的:
switch(imageIndex)
{
case 0:
imageUrl = "Assets/Image1.png";
break;
case 1:
imageUrl = "Assets/Image1.png";
break;
case 2:
imageUrl = "Assets/Image1.png";
break;
}
ITileWIdeImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01();
tileContent.TextCaptionWrap.Text = "Hello";
tileContent.Image.Src = imageUrl;
tileContent.Image.Alt = "";
ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage();
squareContent.Image.Src = imageUrl;
squareContent.Image.Alt = "";
tileContent.SquareContent = squareContent;
var updater = TileUpdateManager.CreateTileUpdaterForApplication();
updater.EnableNotificationQueue(true);
updater.AddToSchedule(
new ScheduledTileNotification(
tileContent.CreateNotification(),
DateTime.Now.AddSeconds(10))
{
ExpirationTime=DateTimeOffset.UtcNow.AddSeconds(20)
});
这将导致您在启动应用程序10秒后收到通知。它将在10秒后过期。
(另外,也许您应该研究后台服务,因为这个特定的解决方案可能不是您想要的最佳...)