正在等待更新的应用通知

可以使用 PendingUpdate 在应用通知中创建多步骤交互。 例如,可以创建一系列通知,其中后续通知依赖于先前通知的响应。

待处理更新的 Toast

有关应用通知的详细信息,请参阅 应用通知概述

概述

实现使用挂起更新作为其激活后行为的通知:

  1. 在您的后台激活按钮中,指定 afterActivationBehaviorpendingUpdate
  2. 发送通知时,请分配 标记 (以及可选的 )。
  3. 当用户单击按钮时,您的后台任务将被激活,通知会在屏幕上保持待定更新状态。
  4. 在后台任务中,使用相同的 标记 发送包含新内容的新通知,以替换挂起的通知。

设置挂起的更新行为

注释

AppNotificationButton 当前 AfterActivationBehavior不支持 。 直接将 XML 有效负载与 AppNotification 构造函数一起使用,以在按钮上设置 afterActivationBehavior="pendingUpdate"

在你的后台激活按钮上,将afterActivationBehavior设置为pendingUpdate。 这仅适用于具有activationType="background"的按钮。

using Microsoft.Windows.AppNotifications;

string xml = @"
<toast>
  <visual>
    <binding template='ToastGeneric'>
      <text>Would you like to order lunch today?</text>
    </binding>
  </visual>
  <actions>
    <action
      content='Yes'
      arguments='action=orderLunch'
      activationType='background'
      afterActivationBehavior='pendingUpdate'/>
    <action
      content='No'
      arguments='action=cancelLunch'
      activationType='background'/>
  </actions>
</toast>";

var notification = new AppNotification(xml);
notification.Tag = "lunch";

AppNotificationManager.Default.Show(notification);

将通知替换为新内容

当用户单击按钮时,将触发您的后台任务,并通过发送具有相同 标记的新通知来替换该通知。 使用AppNotificationBuilder.MuteAudio来在通知替换过程中静音,以响应按钮点击,因为用户已在与通知进行互动。

var notification = new AppNotificationBuilder()
    .AddText("Ordering your lunch...")
    .MuteAudio()
    .BuildNotification();

notification.Tag = "lunch";

AppNotificationManager.Default.Show(notification);

另见