2

在 Windows 8 中更新动态磁贴时,我不知道如何同时更新“大”和“小”尺寸的磁贴。

我希望将我的应用固定在小模式下的用户知道我的程序中有多少项目可供查看,而将我的应用固定在大模式下的用户既有这些,也有一些示例项目标题。

但是,无论我做什么,似乎只有一个磁贴更新到达。如何根据我的磁贴大小提供磁贴更新,以便拥有小磁贴或大磁贴的人不会失望?

4

2 回答 2

5

方形和宽磁贴格式的内容可以(并且应该)包含在定义每个磁贴通知的 XML 中。在visual元素下,只需添加两个binding元素:一个使用宽磁贴模板,一个使用方形磁贴模板。

<tile>
    <visual lang="en-US">
        <binding template="TileWideText03">
            <text id="1">Hello World!</text>
        </binding>
        <binding template="TileSquareText04">
            <text id="1">Hello World!</text>
        </binding>
    </visual>
</tile>

NotificationsExtensions 库(在MSDN tile 示例中找到)提供了一个对象模型来轻松操作 XML 并组合方形和宽 tile 内容:

// create the wide template 
ITileWideText03 tileContent = TileContentFactory.CreateTileWideText03(); 
tileContent.TextHeadingWrap.Text = "Hello World!"; 

// create the square template and attach it to the wide template 
ITileSquareText04 squareContent = TileContentFactory.CreateTileSquareText04(); 
squareContent.TextBodyWrap.Text = "Hello World!"; 
tileContent.SquareContent = squareContent; 
于 2012-09-26T15:53:02.607 回答
1

tile XML 需要组合成如下所示:

<tile>
    <visual version="3">
        <binding template="TileSquare150x150Block" fallback="TileSquareBlock">
            <text id="1">01</text> 
            <text id="2">Tue</text> 
        </binding>
        <binding template="TileWide310x150PeekImageAndText01" fallback="TileWidePeekImageAndText01">
            <image id="1" src="ms-appx:///Assets/WideLogo.png" /> 
            <text id="1">some text</text> 
        </binding>
    </visual>
</tile>

现在有很多方法可以让你的 XML 变成这种形式,但我最喜欢的方法是使用NotificationsExtensions 库,因为它封装了 XML 操作。

在项目中引用该库后,您的代码应如下所示:

// create the wide template
ITileWide310x150PeekImageAndText01 wideContent = TileContentFactory.CreateTileWide310x150PeekImageAndText01();
wideContent.TextBodyWrap.Text = "some text";
wideContent.Image.Src = "ms-appx:///Assets/WideLogo.png";

// create the square template and attach it to the wide template 
ITileSquare150x150Block squareContent = TileContentFactory.CreateTileSquare150x150Block();
squareContent.TextBlock.Text = "01";
squareContent.TextSubBlock.Text = "Tue";
wideContent.Square150x150Content = squareContent;

var tn = new TileNotification(wideContent.GetXml());
TileUpdateManager.CreateTileUpdaterForApplication("App").Clear();
TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tn);
于 2015-08-04T10:53:11.340 回答