Share via


AppNotificationBuilder.SetTag(String) Method

Definition

Sets the tag identifier for an app notification.

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

Parameters

value
String

Platform::String

winrt::hstring

A string identifying the tag associated with the app notification.

Returns

Returns the AppNotificationBuilder instance so that additional method calls can be chained.

Examples

The following example demonstrates setting the tag for an app notification.

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

AppNotificationManager.Default.Show(notification);

The resulting XML payload:

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

An example of removing all of the notifications from Notification Center by tag.

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

Remarks

You can use the tag to remove notifications associated with the tag from the Notification Center by calling AppNotificationManager.RemoveByTagAsync or AppNotificationManager.RemoveByTagAndGroupAsync.

For guidance on using the AppNotificationBuilder APIs to create the UI for app notifications, see App notification content.

For reference information about the XML schema for app notifications, see App notification content schema.

Applies to