更新が保留中のアプリ通知

PendingUpdate を使用して、アプリの通知で複数ステップの対話を作成できます。 たとえば、後続の通知が前の通知からの応答に依存する一連の通知を作成できます。

更新が保留中のトースト

アプリ通知の詳細については、「アプリ通知 の概要」を参照してください。

概要

保留中の更新をアクティベーション後の動作として使用する通知を実装するには、次のステップに従ってください。

  1. バックグラウンドのアクティブ化ボタンに、afterActivationBehaviorpendingUpdate に指定します。
  2. 通知を送信するときに タグ (および必要に応じて グループ) を割り当てます。
  3. ユーザーがボタンをクリックすると、バックグラウンド タスクがアクティブになり、通知は保留中の更新状態のままです。
  4. バックグラウンド タスクで、同じ タググループ を使用して新しいコンテンツを含む新しい通知を送信し、保留中の通知を置き換えます。

保留中の更新の動作を設定します

AppNotificationButton は現在、 AfterActivationBehaviorをサポートしていません。 ボタンにを設定するには、afterActivationBehavior="pendingUpdate" コンストラクターで XML ペイロードを直接使用します。

背景のアクティブ化ボタンで、 afterActivationBehaviorpendingUpdate に設定します。 これは、 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);

こちらも参照ください