2012-09-26 35 views
2

在Windows 8中更新活動切片時,我不知道如何同時更新「大」和「小」大小的切片。更新適當大小的活動瓷磚?

我希望擁有我的應用程序以小模式固定的用戶知道我的程序中有多少可用於查看的項目,以及以大模式固定我的應用程序的用戶同時擁有該項目和某些示例項目標題。

但是,無論我做什麼,似乎只有一個更新到達。如何根據我的瓷磚尺寸提供瓷磚更新,以便擁有小瓷磚或大瓷磚的人不會感到失望?

回答

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 tiles sample找到)提供了一個對象模型來容易地操縱XML和結合平方和寬瓦片內容:

// 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; 
1

瓦片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 library,因爲它封裝了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);