2

我正在尝试在运行时更改我的 Windows 8 应用程序上实时磁贴的背景颜色。这可能吗?有人有代码片段吗?

4

3 回答 3

1

背景颜色在应用清单中指定。因此,这似乎是不可能的。

可以通过在运行时使用适当的背景图像(用于颜色)发送自定义时间来模拟相同的情况。这是一种古怪的方法,但我的小脑袋只能想到这种方法。

于 2012-07-09T04:13:15.630 回答
1

假设您已经解决了问题,但我将在此处发布此信息,如果有人遇到此线程可能会很有用。

对于 Primary Tile,Bruno Lemos 的答案是正确的。

对于 Seconday Tiles,我会使用 TileUpdateManager。CreateTileUpdaterForSecondaryTile (Tile2_ID)。

使用 TileNotifications 和 TileUpdaterManager 对我来说立竿见影。

使用 Tile 模板,您必须从模板中修改一些 XML 代码,但您也可以下载NotificationsExtensions NuGet 包并这样做:

var tile2 = TileContentFactory.CreateTileSquare150x150PeekImageAndText01();
tile2.Branding = TileBranding.Name;
tile2.Image.Src = "ms-appx:///assets/Logo-transparent.png"; //Useful to have the same logo image with transparent background and other colors
tile2.TextHeading.Text = "Heading";
tile2.TextBody1.Text = "String1";
tile2.TextBody2.Text = "String2";
tile2.TextBody3.Text = "String3";
var doc = new XmlDocument();
doc.LoadXml(tile2.ToString());
var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile2_id);
updater.EnableNotificationQueueForSquare150x150(true); //enables up to 5 different tile *animations* for 150 square icon, can be enabled for other sizes too
updater.Update(new TileNotification(doc) { Tag = "1" });

上面的代码考虑了之前创建的 SecondaryTile。

您可以在此处查看不同的图标模板:https ://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.notifications.tiletemplatetype.aspx

您只需更改TileContentFactory.CreateNAMEOFTEMPLATE行并填充不同的字符串/图像字段。

可以在此处找到有关EnableNotificationQueue在磁贴中具有超过 1 个动画的信息:https ://msdn.microsoft.com/en-us/library/windows/apps/hh781199.aspx

于 2015-10-22T16:15:15.650 回答
0

对于 Primary / Default Tile,您可以执行@Tilak 所说的操作:创建平铺图像通知并用于TileUpdateManager.CreateTileUpdaterForApplication().Update更新它。

对于 Secondary Tiles,请执行以下操作:

  1. 在应用清单中,将背景颜色设置为“透明”
  2. 在应用清单中,使用具有透明背景的图像

  3. 现在您可以在运行时执行此操作:

var tile = new SecondaryTile("YOUR_TILE_ID"); tile.VisualElements.BackgroundColor = Colors.Red; await tile.UpdateAsync();

问题是:后台没有立即更新,我不知道为什么。但是例如,您可以在退出/登录后看到效果。(使用 Windows 10 测试)

所以这个答案是不完整的,但希望能给像我这样从谷歌来到这里的人提供见解。

@brunolemos

于 2015-02-20T04:09:40.037 回答