Windows 應用程式的徽章通知

A tile with a numeric badge displaying the number 63 to indicate 63 unread mails.
顯示數值徽章的磚
數字 63 表示 63 封未讀郵件。

通知徽章會傳達應用程式專屬的摘要或狀態資訊。 它們可以是數值 (1-99) 或系統提供的字符集。 透過徽章傳達的最佳訊息範例包括線上遊戲中的網路連線狀態、訊息應用程式中的使用者狀態、郵件應用程式中的未讀郵件數量以及社群媒體應用程式中的新貼文數量。

無論應用程式是否正在執行,通知徽章都會顯示在應用程式的工作列圖示上及其開始磚的右下角。 徽章可以顯示在所有尺寸的磚上。

注意

您無法提供自己的徽章影像; 只能使用系統提供的徽章影像。

數值徽章

徽章 XML
1 至 99 之間的數字。 值 0 相當於字符值「none」,並且將清除徽章。 A numeric badge less than 100. <badge value="1"/>
任何大於 99 的數字。 A numeric badge greater than 99. <badge value="100"/>

字符徽章

徽章可以顯示一組不可擴展的狀態字符集,而不是數字。

狀態 圖像 XML
none (未顯示任何徽章。) <badge value="none"/>
活動 <badge value="activity"/>
鬧鐘 <badge value="alarm"/>
警示 <badge value="alert"/>
注意 <badge value="attention"/>
可供使用 <badge value="available"/>
離開 <badge value="away"/>
忙碌 <badge value="busy"/>
error <badge value="error"/>
newMessage <badge value="newMessage"/>
已暫停 <badge value="paused"/>
正在播放 <badge value="playing"/>
離線 (unavailable) <badge value="unavailable"/>

建立徽章

這些範例示範如何建立徽章更新。

建立數值徽章

private void setBadgeNumber(int num)
{

    // Get the blank badge XML payload for a badge number
    XmlDocument badgeXml = 
        BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);

    // Set the value of the badge in the XML to our number
    XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
    badgeElement.SetAttribute("value", num.ToString());

    // Create the badge notification
    BadgeNotification badge = new BadgeNotification(badgeXml);

    // Create the badge updater for the application
    BadgeUpdater badgeUpdater = 
        BadgeUpdateManager.CreateBadgeUpdaterForApplication();

    // And update the badge
    badgeUpdater.Update(badge);

}

建立字符徽章

private void updateBadgeGlyph()
{
    string badgeGlyphValue = "alert";

    // Get the blank badge XML payload for a badge glyph
    XmlDocument badgeXml = 
        BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);

    // Set the value of the badge in the XML to our glyph value
    Windows.Data.Xml.Dom.XmlElement badgeElement = 
        badgeXml.SelectSingleNode("/badge") as Windows.Data.Xml.Dom.XmlElement;
    badgeElement.SetAttribute("value", badgeGlyphValue);

    // Create the badge notification
    BadgeNotification badge = new BadgeNotification(badgeXml);

    // Create the badge updater for the application
    BadgeUpdater badgeUpdater = 
        BadgeUpdateManager.CreateBadgeUpdaterForApplication();

    // And update the badge
    badgeUpdater.Update(badge);

}

清除徽章

private void clearBadge()
{
    BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
}

取得範例程式碼

  • 通知範例
    示範如何建立動態磚、發送徽章更新,以及顯示快顯通知。