Share via


AppNotificationBuilder.SetTag(String) 方法

定义

设置应用通知的标记标识符。

public:
 virtual AppNotificationBuilder ^ SetTag(Platform::String ^ value) = SetTag;
AppNotificationBuilder SetTag(winrt::hstring const& value);
public AppNotificationBuilder SetTag(string value);
function setTag(value)
Public Function SetTag (value As String) As AppNotificationBuilder

参数

value
String

Platform::String

winrt::hstring

一个字符串,标识与应用通知关联的标记。

返回

返回 AppNotificationBuilder 实例,以便可以链接其他方法调用。

示例

以下示例演示如何设置应用通知的 标记。

var notification = new AppNotificationBuilder()
    .AddText("Notification text.")
    .SetTag("Tag value")
    .BuildNotification();

AppNotificationManager.Default.Show(notification);

生成的 XML 有效负载:

<toast>
    <visual>
        <binding template='ToastGeneric'>
            <text>Notification text.</text>
        </binding>
    </visual>
</toast>

通过标记从通知中心删除所有通知的示例。

await AppNotificationManager.Default.RemoveByTagAsync("Tag value");

注解

可以使用 标记通过调用 AppNotificationManager.RemoveByTagAsyncAppNotificationManager.RemoveByTagAndGroupAsync 从通知中心删除与标记关联的通知。

有关使用 AppNotificationBuilder API 创建应用通知 UI 的指导,请参阅 应用通知内容

有关应用通知的 XML 架构的参考信息,请参阅 应用通知内容架构

适用于