如何在 Windows 10 uwp 中的辅助磁贴上显示多个图像

本文关键字:显示 图像 Windows uwp | 更新日期: 2023-09-27 18:31:23

我正在尝试创建一个辅助磁贴,它像在照片应用程序中一样旋转显示图片。我试过这样的事情:

SecondaryTile tile = GenerateSecondaryTile("NewTile", "SecondaryTile");
await tile.RequestCreateAsync();
var ImageUrl = selectedFileList.ElementAt(0).Path;
string tileXmlString =
"<tile>"
+ "<visual>"
+ "<binding template='TileSmall'>"
+ "<image  src='" + selectedFileList.ElementAt(0).Path + "' alt='image'/>"
+ "<image  src='" + selectedFileList.ElementAt(1).Path + "' alt='image'/>"
+ "<image  src='" + selectedFileList.ElementAt(2).Path + "' alt='image'/>"
+ "<image  src='" + selectedFileList.ElementAt(3).Path + "' alt='image'/>"
+ "<image src='" + selectedFileList.ElementAt(4).Path + "' alt='image'/>"
+ "</binding>"
+ "</visual>"
+ "</tile>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(tileXmlString);
TileNotification notifyTile = new TileNotification(xmlDoc);
TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId).Update(notifyTile);

我尝试将类型设置为背景和窥视,但它没有给出所需的结果。而且我也不想使用后台任务,因为我的应用程序已经使用了一个后台任务,我不想增加可能导致任务完全失败的开销。我不介意图像是否像早期的Windows Phone 8.1那样限制为5

供参考:查看此内容:跳至0:30

如何在 Windows 10 uwp 中的辅助磁贴上显示多个图像

这适用于主磁贴,但它的工作方式应该相同。创建自己的 XML 模板,然后引用您的图像。启用通知队列,然后使用磁贴通知更新磁贴。最多执行此操作五次,即可将五个图像放在动态磁贴堆栈上。

var myStorageFile = await Package.Current.InstalledLocation.GetFileAsync("LiveTileTemplate.xml");
string liveTileTemplate = await FileIO.ReadTextAsync(myStorageFile);
liveTileTemplate = liveTileTemplate.Replace("squareImageSource", FilePathFullPrefix + GetFilePathSquareTile(imageID));
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
TileUpdateManager.CreateTileUpdaterForApplication().Update(new TileNotification(mergedXML));