var tileAttributes = tileXml.getElementsByTagName("text"); tileAttributes[0].appendChild(tileXml.createTextNode("Hello World! My very own tile notification"));
基於已經指定的 XML 內容創建通知
var tileNotification = new Notifications.TileNotification(tileXml);
為通知設定到期時間 該通知將在十分鐘內到期並從磁貼中刪除。
var currentTime = new Date(); tileNotification.expirationTime = new Date(currentTime.getTime() + 600 * 1000);
使用 Windows 運行時 API 創建採用 JavaScript 的基本 Modern 風格套用的功能。
若要使此頁上顯示的示例代碼正常工作,則必須在檔案中包含以下行:
var Notifications = Windows.UI.Notifications;
說明
步驟 1: 定義加寬磁貼 此示例選擇模板,檢索模板文本和圖像元素,以及為這些元素分配值。
var tileXml = Notifications.TileUpdateManager.getTemplateContent(Notifications.TileTemplateType.tileWideImageAndText01); // Get the text attributes for this template and fill them in.var tileTextAttributes = tileXml.getElementsByTagName("text"); tileTextAttributes[0].appendChild(tileXml.createTextNode("This tile notification uses ms-resource images")); // Get the image attributes for this template and fill them in.var tileImageAttributes = tileXml.getElementsByTagName("image"); tileImageAttributes[0].setAttribute("src", "ms-resource:images/redWide.png");
步驟 2: 定義正方形磁貼 此示例重複執行僅圖像正方形磁貼的前面步驟。
var squareTileXml = Notifications.TileUpdateManager.getTemplateContent(Notifications.TileTemplateType.tileSquareImage); var squareTileImageAttributes = squareTileXml.getElementsByTagName("image"); squareTileImageAttributes[0].setAttribute("src", "ms-resource:images/graySquare.png");
var template = Windows.UI.Notifications.TileTemplateType.tileWideText03; var tileXml = Windows.UI.Notifications.TileUpdateManager.getTemplateContent(template); // TODO: Fill in the template with your tile content.// TODO: Define a square tile and add it to tileXML.var tileNotification = new Windows.UI.Notifications.TileNotification(tileXml);