Share via


AppNotificationBuilder.AddArgument(String, String) 方法

定义

将由键/值对组成的参数添加到应用通知的 XML 有效负载。

public:
 virtual AppNotificationBuilder ^ AddArgument(Platform::String ^ key, Platform::String ^ value) = AddArgument;
AppNotificationBuilder AddArgument(winrt::hstring const& key, winrt::hstring const& value);
public AppNotificationBuilder AddArgument(string key, string value);
function addArgument(key, value)
Public Function AddArgument (key As String, value As String) As AppNotificationBuilder

参数

key
String

Platform::String

winrt::hstring

一个包含参数键的字符串。

value
String

Platform::String

winrt::hstring

一个包含参数值的字符串。

返回

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

示例

以下示例演示了如何使用此方法向应用通知添加参数。

var notification = new AppNotificationBuilder()
    .AddText("Send a message.")
    .AddTextBox("textBox")
    .BuildNotification();

AppNotificationManager.Default.Show(notification);

生成的 XML 有效负载:

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

注解

当用户单击通知时,使用此方法添加的应用通知参数将传递到激活的应用程序。 可以向每个通知添加多个参数。 通过访问 AppNotificationActivatedEventArgs.Arguments 属性,检索使用此方法添加的参数。

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

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

适用于