我的应用程序中有什么方形和诡计瓦片。但是当我更新例如宽实时瓷砖正方形实时瓷砖变成默认应用瓷砖。当我更新宽方形瓷砖宽瓷砖成为默认。
用于宽磁贴更新的代码
var TileMgr = TileUpdateManager.CreateTileUpdaterForApplication();
var tileTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Image);
XmlElement tmp = tileTemplate.GetElementsByTagName("visual")[0] as XmlElement;
tmp.SetAttribute("branding", "none");
var tileImageAttributes = tileTemplate.GetElementsByTagName("image");
tmp = tileImageAttributes[0] as XmlElement;
tmp.SetAttribute("src", "UpdatedLiveTileWide.png");
var notification = new TileNotification(tileTemplate);
TileMgr.Update( notification);
方块更新的代码
var TileMgr = TileUpdateManager.CreateTileUpdaterForApplication();
var tileTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image);
XmlElement tmp = tileTemplate.GetElementsByTagName("visual")[0] as XmlElement;
tmp.SetAttribute("branding", "none");
var tileImageAttributes = tileTemplate.GetElementsByTagName("image");
tmp = tileImageAttributes[0] as XmlElement;
tmp.SetAttribute("src", "UpdatedLiveTile.png");
var notification = new TileNotification(tileTemplate);
TileMgr.Update(notification);
当我执行“方块更新的代码”时,我得到了这样的sqare tile:
这么宽的瓷砖
之后我执行“宽瓷砖更新代码” 得到这么宽的瓷砖:
和这样的方形瓷砖:
答案 0 :(得分:1)
如果要更新多种类型的磁贴,则需要在单个TileNotification
中进行更新。未在TileNotification
中设置的任何图块信息将重置为默认值。为此,您需要创建XmlDocument
,使其在一个“可视”元素下具有不同的“绑定”元素(对应于每种类型的图块)。
在你的情况下它应该是这样的
//Create medium tile update
XmlDocument mediumTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image);
(mediumTemplate.GetElementsByTagName("image")[0] as XmlElement).SetAttribute("src", "UpdatedLiveTile.png");
//Create wide tile update
XmlDocument wideTemplate = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Image);
(wideTemplate.GetElementsByTagName("image")[0] as XmlElement).SetAttribute("src", "UpdatedLiveTileWide.png");
//Import the 'binding' node from wideTemplate
var wideBinding = mediumTemplate.ImportNode(wideTemplate.GetElementsByTagName("binding")[0], true);
//Add it under 'visual' node in mediumTemplate
var visualElement = mediumTemplate.GetElementsByTagName("visual")[0];
visualElement.AppendChild(wideBinding);
(visualElement as XmlElement).SetAttribute("branding", "none");
//Now the mediumTemplate has bindings for both medium and wide tile
//Create tile notification using mediumTemplate and update
TileNotification notification = new TileNotification(mediumTemplate);
TileUpdateManager.CreateTileUpdaterForApplication().Update(notification);