动态磁贴中的TileSquare71x71IconWithBadge模板的XML

时间:2014-07-27 00:08:28

标签: xml templates windows-phone-8.1 live-tile

Microsoft have a long list of great Live Tile templates,但没有关于如何制作它们的真正指南。我正在尝试将TileSquare71x71IconWithBadge的XML放在一起,但是该列表中缺少示例XML。那XML会是什么样的?我得到的最接近的是这个,但它不起作用:

<?xml version="1.0" encoding="utf-8" ?>
<tile>
  <visual version="3">
    <binding template="TileSquare71x71IconWithBadge" fallback="null">
      <image id="1" src="image1" alt="alt text"/>
      <text id="1">36</text>
    </binding>
  </visual>
</tile>

对此瓷砖的唯一更改是36位于瓷砖的左下角;但是,他们所有的示例模板xml文件都运行良好。

(注意:我所追求的模板位于页面的最底部。)

enter image description here

4 个答案:

答案 0 :(得分:0)

您必须单独发送徽章通知。以下是更新实时图块后如何发送徽章通知的代码

 XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); 
        XmlElement badgeElement = (XmlElement)badgeXml.SelectSingleNode("/badge");
        badgeElement.SetAttribute("value", "55");
        BadgeNotification badge = new BadgeNotification(badgeXml);
        BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);

希望它有所帮助!

答案 1 :(得分:0)

徽章必须单独发送,写在说明中:

badge

答案 2 :(得分:0)

瓷砖的文档是一场彻底的灾难!这是我正在使用的代码,我想我必须从其中一个示例项目中提取它,因为它没有列在网页本身的任何位置。

    public static TileNotification CreateMediumTile(int count)
    {
        // Get an XML DOM version of a specific template by using getTemplateContent.
        var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150IconWithBadge);

        // You will need to look at the template documentation to know how many text fields a particular template has.
        // Get the text attribute for this template and fill it in.
        var tileImage = tileXml.GetElementsByTagName("image");
        ((XmlElement)tileImage[0]).SetAttribute("src", "ms-appx:///Assets/SquareTile71x71.png");
        ((XmlElement)tileImage[0]).SetAttribute("alt", "My App Icon");

        BadgeNotification badge;

        if (count > 0)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<badge version='3' value='" + count + "'/>");
            badge = new BadgeNotification(xmlDoc);

        }
        else
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<badge version='3' value='none'/>");
            badge = new BadgeNotification(xmlDoc);
        }

        // Send the notification to the application’s tile.
        BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge);

        // Create the notification from the XML.
        var tileNotification = new TileNotification(tileXml);

        return tileNotification;
    }

答案 3 :(得分:0)

TileTemplateType枚举不包含徽章类型TileSquare71x71IconWithBadge,TileSquare150x150IconWithBadge和TileWide310x150IconWithBadgeAndText但MSDN页面&#39; The tile template catalog&#39;包含此tile定义的xml描述。并且可以使用代码

构建TileNotification
var xml = "<tile><visual version=\"3\"><binding template=\"TileSquare71x71IconWithBadge\"><image id=\"1\" src=\"ms-appx:///Assets/BageLogo.scale-240.png\" alt=\"alt text\"/></binding></visual></tile>";

var tile = new XmlDocument();
tile.LoadXml(xml);
var tileNotification = new TileNotification(tile);

TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

注意在这种情况下,该图像是小型图标的路径。

还应使用BadgeUpdateManager单独更新徽章编号。在之前的答案中张贴了徽章更新代码...