3

比如说,我想定期更新 Windows 8 动态磁贴,比如 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());

提前致谢。

4

2 回答 2

0

Don't use Dispatcher Timer as it will slow your app. You can use the following in your page Initializer:

TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
于 2012-07-22T15:51:53.627 回答
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 秒后过期。

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

于 2012-07-30T15:19:57.917 回答