windows-8 - Windows 8 Live Tile 的定期更新

标签 windows-8 microsoft-metro

假设,我想定期更新 Windows 8 动态磁贴,比如 10 秒后。有什么办法可以实现这一点吗?我在 Windows 8 中使用 Metro xaml C#。

这是我在调度程序计时器的 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());

提前致谢。

最佳答案

您应该这样做:

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秒就会过期。

(另外,也许您应该研究一下后台服务,因为这个特定的解决方案可能不是您想要的最佳解决方案......)

关于windows-8 - Windows 8 Live Tile 的定期更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11599356/

相关文章:

c++ - Windows 路径处理库

c# - XAML数据绑定(bind),对象与目标类型不匹配

c# - 在 Windows 8 的 Metro 应用程序中拖动用户控件

http-post - 如何在 Windows 8 Metro 中执行 post 方法?

c# - 在 WinRT 应用程序中即时本地化

c# - 从 C# 显示关闭对话框

javascript - 如果音频停止,如何取消选中复选框?

c# - : the attachable property triggers was not found in style in a Grid Application如何解决

c# - Windows 8 Live Tile - 删除文本和小图标?

c# - Windows 8 中的 Windows Azure 和 Metro 风格的应用程序