Windows 应用的徽章通知

通知徽章传达特定应用的摘要或状态信息。 它们可以是数字(1-99)或一组系统提供的标志符号之一。 最好通过徽章传达的信息示例包括在线游戏中的网络连接状态、消息应用中的用户状态、邮件应用中的未读邮件数以及社交媒体应用中的新帖子数。

无论应用是否正在运行,通知徽章都会显示在应用的任务栏图标上及其开始屏幕磁贴的右下角。 徽章可以显示在所有磁贴大小上。

Note

无法提供自己的锁屏提醒图像;只能使用系统提供的锁屏提醒图像。

Numeric badges

Value Badge XML
从 1 到 99 的数字。 值 0 等效于字形值“无”,并将清除徽章。 小于 100 的数字徽章。 <badge value="1"/>
任何大于 99 的数字。 数字徽章,数量超过 99。 <badge value="100"/>

Glyph badges

徽章可以显示一组不可扩展的状态图标,而不是数字。

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

获取示例代码