共用方式為


Windows 應用程式的徽章通知

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

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

Note

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

數字徽章

Value Badge XML
1 至 99 之間的數字。 數值為 0 相當於字形值「none」並會清除徽章。 小於 100 的數值徽章。 <badge value="1"/>
任何大於 99 的數字。 大於 99 的數值徽章。 <badge value="100"/>

符號徽章

徽章可以顯示一組不可延伸的狀態圖標,這是取代數字的選項。

Status Glyph XML
none (未顯示任何徽章。) <badge value="none"/>
活動 表示「活動」狀態的字元徽章。 <badge value="activity"/>
alarm 表示「警示」狀態的字元徽章。 <badge value="alarm"/>
警示 表示「警示」狀態的字元徽章。 <badge value="alert"/>
attention 表示「注意」狀態的字元徽章。 <badge value="attention"/>
available 表示「可用」狀態的字元徽章。 <badge value="available"/>
away 表示「離開」狀態的字元徽章。 <badge value="away"/>
busy 表示「忙碌」狀態的字元徽章。 <badge value="busy"/>
錯誤 表示「錯誤」狀態的字元徽章。 <badge value="error"/>
newMessage 表示 'newMessage' 狀態的字元徽章。 <badge value="newMessage"/>
paused 表示「已暫停」狀態的字元徽章。 <badge value="paused"/>
playing 圖像徽章,表示「正在播放」狀態。 <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();
}

取得範例程式碼

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