Updating a live tile in its proper size?

后端 未结 2 497
南方客
南方客 2020-12-21 17:40

When updating live tiles in Windows 8, I don\'t know how to update the tile in both the \"large\" and \"small\" size at the same time.

I would like users who have my

相关标签:
2条回答
  • 2020-12-21 18:39

    Content for both the square and wide tile format can (and should) be included in the XML defining each tile notification. Under the visual element, simply add two binding elements: one using a wide tile template, and one using a square tile template.

    <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>
    

    The NotificationsExtensions library (found in the MSDN tiles sample) provides an object model to easily manipulate the XML and combine square and wide tile content:

    // 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; 
    
    0 讨论(0)
  • 2020-12-21 18:40

    The tile XML needs to be combined to look like this:

    <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>
    

    Now there are many ways you can use to get your XML into this form, but my favourite way is to use the use the NotificationsExtensions library as it encapsulates the XML manipilation.

    Once you reference the library in your project your code should look like this:

    // 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);
    
    0 讨论(0)
提交回复
热议问题