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