快顯通知標頭Toast headers

您可以在通知上使用快顯通知標頭,來視覺分組控制中心內的相關通知。You can visually group a set of related notifications inside Action Center by using a toast header on your notifications.

重要

需要 Desktop Creators Update 和 Notifications 程式庫 1.4.0 :您必須執行桌上型電腦組建 15063 或更新版本,才能看見快顯通知標頭。Requires Desktop Creators Update and 1.4.0 of Notifications library : You must be running Desktop build 15063 or higher to see toast headers. 您必須使用版本 1.4.0 或更高版本的 UWP Community Toolkit Notifications NuGet 程式庫,以便在快顯通知內容中建構標頭。You must use version 1.4.0 or higher of the UWP Community Toolkit Notifications NuGet library to construct the header in your toast's content. 只有桌上型電腦才支援標頭。Headers are only supported on Desktop.

如下所示,群組交談已整合至單一標頭「露營!!」下方。As seen below, this group conversation is unified under a single header, "Camping!!". 交談中的每個個別訊息都是不同的快顯通知,但共用相同的快顯通知標頭。Each individual message in the conversation is a separate toast notification sharing the same toast header.

Toasts with header

您也可以選擇依照類別來視覺分組您的通知,例如航班提醒、包裹追蹤等。You can also choose to visually group your notifications by category too, like flight reminders, package tracking, and more.

新增標頭到快顯通知Add a header to a toast

以下是將標頭加入快顯通知的方式。Here's how you add a header to a toast notification.

注意

只有桌上型電腦才支援標頭。Headers are only supported on Desktop. 不支援標頭的裝置會直接忽略標頭。Devices that don't support headers will simply ignore the header.

new ToastContentBuilder()
    .AddHeader("6289", "Camping!!", "action=openConversation&id=6289")
    .AddText("Anyone have a sleeping bag I can borrow?");

總結來說...In summary...

  1. 新增 HeaderToastContentAdd the Header to your ToastContent
  2. 指派必要的 IdTitleArguments 屬性Assign the required Id , Title , and Arguments properties
  3. 傳送您的通知 (深入了解)Send your notification (learn more)
  4. 在另一個通知上,使用相同標頭 Id 將它們整合在同一個標頭下。On another notification, use the same header Id to unify them under the header. Id 是用來判斷是否應將通知分組在一起的唯一屬性,這表示 TitleArguments 可以不同。The Id is the only property used to determine whether the notifications should be grouped, meaning the Title and Arguments can be different. 會使用來自群組中最新通知的 TitleArgumentsThe Title and Arguments from the most recent notification within a group are used. 如果該通知被移除,則 TitleArguments 會退回下一個最新的通知。If that notification gets removed, then the Title and Arguments falls back to the next most recent notification.

處理來自標頭的啟用Handle activation from a header

標頭可供使用者點按,因此使用者可以按下標頭以從您的應用程式了解更多資訊。Headers are clickable by users, so that the user can click the header to find out more from your app.

因此,應用程式可以在標頭上提供 Arguments ,類似於快顯本身的啟動引數。Therefore, apps can provide Arguments on the header, similar to the launch arguments on the toast itself.

啟用的處理方式與 一般快顯通知啟用相同,這表示您可以在 App.xaml.csOnActivated 方法中擷取這些引數,如同當使用者按下快顯通知的主體或快顯通知的按鈕時您所執行的動作。Activation is handled identical to normal toast activation, meaning you can retrieve these arguments in the OnActivated method of App.xaml.cs just like you do when the user clicks the body of your toast or a button on your toast.

protected override void OnActivated(IActivatedEventArgs e)
{
    // Handle toast activation
    if (e is ToastNotificationActivatedEventArgs)
    {
        // Arguments specified from the header
        string arguments = (e as ToastNotificationActivatedEventArgs).Argument;
    }
}

其他資訊Additional info

標頭會在視覺上分隔與分組通知。The header visually separates and groups notifications. 這不會變更其他任何邏輯,包括應用程式可以擁有的通知數目上限 (20) 以及通知清單的先進先出行為。It doesn't change any other logistics about the maximum number of notifications an app can have (20) and the first-in-first-out behavior of the notifications list.

標頭中的通知順序如下所示... 對於特定的應用程式,會首先出現來自應用程式的最新通知 (以及整個標頭群組,如果屬於標題的一部分)。The order of notifications within headers are as follows... For a given app, the most recent notification from the app (and the entire header group if part of a header) will appear first.

Id 可以是您選擇的任何字串。The Id can be any string you choose. ToastHeader 中的任何屬性沒有長度或字元限制。There are no length or character restrictions on any of the properties in ToastHeader . 唯一限制是您的整個 XML 快顯通知內容不可大於 5 KB。The only constraint is that your entire XML toast content cannot be larger than 5 KB.

建立標頭不會變更 [查看更多] 按鈕出現之前顯示在控制中心的通知數目 (這個數字預設為 3,使用者可以在通知的系統設定中針對每個應用程式進行設定)。Creating headers doesn't change the number of notifications shown inside Action Center before the "See more" button appears (this number is 3 by default and can be configured by the user for each app in system Settings for notifications).

按一下標頭,如同按一下應用程式標題,並不會清除屬於此標頭的任何通知 (您的應用程式應該使用快顯通知 API 來清除相關通知)。Clicking on the header, just like clicking on the app title, does not clear any notifications belonging to this header (your app should use the toast APIs to clear the relevant notifications).