快顯通知內容Toast content

調適型和互動式快顯通知可讓您使用文字、影像和按鈕/輸入建立彈性通知。Adaptive and interactive toast notifications let you create flexible notifications with text, images, and buttons/inputs.

重要 APIUWP Community Toolkit Notifications NuGet 套件Important APIs: UWP Community Toolkit Notifications nuget package

注意

若要查看 Windows 8.1 和 Windows Phone 8.1 的舊版範本,請參閱舊版快顯範本目錄To see the legacy templates from Windows 8.1 and Windows Phone 8.1, see the legacy toast template catalog.

開始使用Getting started

安裝通知程式庫。Install Notifications library. 如果您想要使用 C# 而不是 XML 產生通知,請安裝名稱為 Microsoft.Toolkit.Uwp.Notifications 的 NuGet 套件 (搜尋 "notifications uwp")。If you'd like to use C# instead of XML to generate notifications, install the NuGet package named Microsoft.Toolkit.Uwp.Notifications (search for "notifications uwp"). 本文中所提供的 C# 範例使用該 NuGet 套件 1.0.0 版本。The C# samples provided in this article use version 1.0.0 of the NuGet package.

安裝通知視覺化檢視。Install Notifications Visualizer. 這個免費的 UWP 應用程式透過在您編輯快顯通知時提供即時視覺預覽 (類似 Visual Studio 的 XAML 編輯器/設計檢視),可協助您設計互動式快顯通知。This free UWP app helps you design interactive toast notifications by providing an instant visual preview of your toast as you edit it, similar to Visual Studio's XAML editor/design view. 如需詳細資訊,請參閱通知視覺化工具從 Microsoft Store 下載通知視覺化工具See Notifications Visualizer for more information, or download Notifications Visualizer from the Store.

傳送快顯通知Sending a toast notification

若要了解如何傳送通知,請參閱傳送本機快顯通知To learn how to send a notification, see Send local toast. 本文件僅探討建立快顯通知內容。This documentation only covers creating the toast content.

快顯通知結構Toast notification structure

快顯通知是一些如 Tag/Group 等資料屬性 (讓您識別通知) 與快顯通知內容的組合。Toast notifications are a combination of some data properties like Tag/Group (which let you identify the notification) and the toast content.

快顯通知內容的核心元件為...The core components of toast content are...

  • launch:這會定義使用者按一下快顯通知時,要將哪些引數傳回到 App,讓您深度連結至快顯通知已在顯示的正確內容中。launch: This defines what arguments will be passed back to your app when the user clicks your toast, allowing you to deep link into the correct content that the toast was displaying. 若要深入了解,請參閱傳送本機快顯通知To learn more, see Send local toast.
  • visual:快顯通知的視覺效果部分,其中會有包含文字和影像的泛型繫結。visual: The visual portion of the toast, including the generic binding that contains text and images.
  • actions:快顯通知的互動部分,包括輸入和動作。actions: The interactive portion of the toast, including inputs and actions.
  • audio:控制向使用者顯示快顯通知時播放的音效。audio: Controls the audio played when the toast is shown to the user.

快顯通知內容是以原始 XML 定義,但是您可以使用我們的 NuGet 程式庫 取得 C# (or C++) 物件模型來建構快顯通知內容。The toast content is defined in raw XML, but you can use our NuGet library to get a C# (or C++) object model for constructing the toast content. 本文記載快顯通知內容的相關資訊,應有盡有。This article documents everything that goes within the toast content.

ToastContent content = new ToastContent()
{
    Launch = "app-defined-string",
 
    Visual = new ToastVisual()
    {
        BindingGeneric = new ToastBindingGeneric() { ... }
    },
 
    Actions = new ToastActionsCustom() { ... },
 
    Audio = new ToastAudio() { ... }
};
<toast launch="app-defined-string">

  <visual>
    <binding template="ToastGeneric">
      ...
    </binding>
  </visual>

  <actions>
    ...
  </actions>

  <audio src="ms-winsoundevent:Notification.Reminder"/>

</toast>

以下是以快顯通知內容的視覺呈現方式:Here is a visual representation of the toast's content:

快顯通知結構

VisualVisual

每個快顯通知都必須指定視覺效果,您必須在其中提供可包含文字、影像等項目的泛型快顯通知繫結。Each toast must specify a visual, where you must provide a generic toast binding, which can contain text, images, and more. 這些元素會呈現在各種不同 Windows 裝置,包括桌上型電腦、手機、平板電腦和 Xbox。These elements will be rendered on various Windows devices, including desktop, phones, tablets, and Xbox.

如需了解視覺區段及其子元素支援的所有屬性,請參閱結構描述For all attributes supported in the visual section and its child elements, see the schema documentation.

快顯通知上的 App 身分識別會透過 App 圖示來傳達。Your app's identity on the toast notification is conveyed via your app icon. 不過,如果您使用 App 標頭覆寫,則會在文字行下方顯示 App 名稱。However, if you use the app logo override, we will display your app name beneath your lines of text.

一般快顯通知的應用程式身分識別App identity for normal toast 具備 appLogoOverride 的應用程式身分識別App identity with appLogoOverride
notification without appLogoOverride notification with appLogoOverride

文字元素Text elements

每個快顯通知都必須至少有一個文字元素,並且可以包含兩個類型皆為 AdaptiveText 的額外文字元素。Each toast must have at least one text element, and can contain two additional text elements, all of type AdaptiveText.

Toast with title and description

從 Windows 10 年度更新版以後,您可以使用文字的 HintMaxLines 屬性控制顯示多少行文字。Since the Windows 10 Anniversary Update, you can control how many lines of text are displayed by using the HintMaxLines property on the text. 預設 (及上限) 為標題最多 2 行文字,以及兩個額外描述元素 (第二個和第三個 AdaptiveText) 最多 4 行 (合併)。The default (and maximum) is up to 2 lines of text for the title, and up to 4 lines (combined) for the two additional description elements (the second and third AdaptiveText).

new ToastBindingGeneric()
{
    Children =
    {
        new AdaptiveText()
        {
            Text = "Adaptive Tiles Meeting",
            HintMaxLines = 1
        },

        new AdaptiveText()
        {
            Text = "Conf Room 2001 / Building 135"
        },

        new AdaptiveText()
        {
            Text = "10:00 AM - 10:30 AM"
        }
    }
}
<binding template="ToastGeneric">
    <text hint-maxLines="1">Adaptive Tiles Meeting</text>
    <text>Conf Room 2001 / Building 135</text>
    <text>10:00 AM - 10:30 AM</text>
</binding>

App 標誌覆寫App logo override

根據預設,快顯通知會顯示 App 的標誌。By default, your toast will display your app's logo. 不過,您可以將此標誌覆寫為您自己的 ToastGenericAppLogo 影像。However, you can override this logo with your own ToastGenericAppLogo image. 例如,如果這是來自某個人的通知,我們建議以那個人的相片來覆寫 App 標誌。For example, if this is a notification from a person, we recommend overriding the app logo with a picture of that person.

Toast with app logo override

您可以使用 HintCrop 屬性來變更影像的裁剪。You can use the HintCrop property to change the cropping of the image. 例如,Circle 會產生圓形裁剪的影像。For example, Circle results in a circle-cropped image. 否則,影像為正方形。Otherwise, the image is square. 100% 縮放比例的影像尺寸為 48x48 像素。Image dimensions are 48x48 pixels at 100% scaling.

new ToastBindingGeneric()
{
    ...

    AppLogoOverride = new ToastGenericAppLogo()
    {
        Source = "https://picsum.photos/48?image=883",
        HintCrop = ToastGenericAppLogoCrop.Circle
    }
}
<binding template="ToastGeneric">
    ...
    <image placement="appLogoOverride" hint-crop="circle" src="https://picsum.photos/48?image=883"/>
</binding>

主角圖像Hero image

年度更新版的新功能:快顯通知可以顯示主角影像,這是在快顯通知橫幅和控制中心內顯示得很醒目的精選 ToastGenericHeroImageNew in Anniversary Update: Toasts can display a hero image, which is a featured ToastGenericHeroImage displayed prominently within the toast banner and while inside Action Center. 100% 縮放比例的影像尺寸為 364x180 像素。Image dimensions are 364x180 pixels at 100% scaling.

Toast with hero image
new ToastBindingGeneric()
{
    ...

    HeroImage = new ToastGenericHeroImage()
    {
        Source = "https://picsum.photos/364/180?image=1043"
    }
}
<binding template="ToastGeneric">
    ...
    <image placement="hero" src="https://picsum.photos/364/180?image=1043"/>
</binding>

內嵌影像Inline image

您可以提供會在您展開快顯通知時出現的全寬內嵌影像。You can provide a full-width inline-image that appears when you expand the toast.

Toast with additional image
new ToastBindingGeneric()
{
    Children =
    {
        ...

        new AdaptiveImage()
        {
            Source = "https://picsum.photos/360/202?image=1043"
        }
    }
}
<binding template="ToastGeneric">
    ...
    <image src="https://picsum.photos/360/202?image=1043" />
</binding>

影像大小限制Image size restrictions

您在快顯通知中使用的影像可源自...The images you use in your toast notification can be sourced from...

  • http://http://
  • ms-appx:///ms-appx:///
  • ms-appdata:///ms-appdata:///

對於 http 和 https 遠端網頁影像,每個個別影像的檔案大小有一些限制。For http and https remote web images, there are limits on the file size of each individual image. 在 Fall Creators Update (16299) 中,我們將一般連線的限制提高到 3 MB,而計量付費連線的限制提高到 1 MB。In the Fall Creators Update (16299), we increased the limit to be 3 MB on normal connections and 1 MB on metered connections. 在此之前,影像一律限制於 200 KB。Before that, images were always limited to 200 KB.

一般連線Normal connection 計量付費連線Metered connection Fall Creators Update 之前Before Fall Creators Update
3 MB3 MB 1 MB1 MB 200 KB200 KB

如果影像超過檔案大小、無法下載或逾時,影像將被捨棄,並顯示通知的其餘部分。If an image exceeds the file size, or fails to download, or times out, the image will be dropped and the rest of the notification will be displayed.

屬性文字Attribution text

年度更新版的新功能:如果需要參考內容的來源,您可以使用屬性文字。New in Anniversary Update: If you need to reference the source of your content, you can use attribution text. 此文字永遠和通知身分識別或通知時間戳記一起顯示在通知的底部。This text is always displayed at the bottom of your notification, along with your app's identity or the notification's timestamp.

舊版 Windows 不支援文字屬性,文字只是簡單顯示成另一個文字元素 (假設文字元素尚未到達最多三個的限制)。On older versions of Windows that don't support attribution text, the text will simply be displayed as another text element (assuming you don't already have the maximum of three text elements).

Toast with attribution text
new ToastBindingGeneric()
{
    ...

    Attribution = new ToastGenericAttributionText()
    {
        Text = "Via SMS"
    }
}
<binding template="ToastGeneric">
    ...
    <text placement="attribution">Via SMS</text>
</binding>

自訂時間戳記Custom timestamp

Creators Update 的新功能:您現在可以將系統提供的時間戳記覆寫為您自己的準確表示何時產生訊息/資訊/內容的時間戳記。New in Creators Update: You can now override the system-provided timestamp with your own timestamp that accurately represents when the message/information/content was generated. 此時間戳記可顯示在控制中心內。This timestamp is visible within Action Center.

Toast with custom timestamp

若要深入了解使用自訂時間戳記,請參閱快顯通知上的自訂時間戳記To learn more about using a custom timestamp, please see custom timestamps on toasts.

ToastContent toastContent = new ToastContent()
{
    DisplayTimestamp = new DateTime(2017, 04, 15, 19, 45, 00, DateTimeKind.Utc),
    ...
};
<toast displayTimestamp="2017-04-15T19:45:00Z">
  ...
</toast>

進度列Progress bar

建立者更新的新功能:您可以在快顯通知上提供進度列,讓使用者知道如下載作業的進度。New in Creators Update: You can provide a progress bar on your toast notification to keep the user informed of the progress of operations such as downloads.

Toast with progress bar

若要深入了解使用進度列,請參閱快顯通知進度列To learn more about using a progress bar, please see Toast progress bar.

標頭Headers

Creators Update 的新功能:您可以將通知分組在控制中心的標頭下方。New in Creators Update: You can group notifications under headers within Action Center. 例如,您可以將來自某個群組聊天的群組訊息分組在一個標頭下,或將常見主題的通知分組在一個標頭下,以此類推。For example, you can group messages from a group chat under a header, or group notifications of a common theme under a header, or more.

Toasts with header

若要深入了解使用標頭,請參閱快顯通知標頭To learn more about using headers, please see Toast headers.

調適性內容Adaptive content

年度更新版的新功能:除了以上所指定的內容之外,您還可以顯示會在展開快顯通知時顯示的其他調適性內容。New in Anniversary Update: In addition to the content specified above, you can also display additional adaptive content that is visible when the toast is expanded.

這個額外內容是使用 Adaptive 所指定,您可以閱讀調適型磚文件 進行深入了解。This additional content is specified using Adaptive, which you can learn more about by reading the Adaptive Tiles documentation.

請注意,任何調適性內容都必須包含在 AdaptiveGroup 中。Note that any adaptive content must be contained within an AdaptiveGroup. 否則無法使用 Adaptive 呈現出來。Otherwise it will not be rendered using adaptive.

欄和文字元素Columns and text elements

以下是一個使用欄和一些進階調適性文字元素的範例。Here's an example where columns and some advanced adaptive text elements are used. 由於文字元素是在 AdaptiveGroup 內,因此支援所有的豐富調適性樣式屬性。Since the text elements are within an AdaptiveGroup, they support all the rich adaptive styling properties.

Toast with additional text
new ToastBindingGeneric()
{
    Children =
    {
        ...

        new AdaptiveGroup()
        {
            Children =
            {
                new AdaptiveSubgroup()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "52 attendees",
                            HintStyle = AdaptiveTextStyle.Base
                        },
                        new AdaptiveText()
                        {
                            Text = "23 minute drive",
                            HintStyle = AdaptiveTextStyle.CaptionSubtle
                        }
                    }
                },
                new AdaptiveSubgroup()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "1 Microsoft Way",
                            HintStyle = AdaptiveTextStyle.CaptionSubtle,
                            HintAlign = AdaptiveTextAlign.Right
                        },
                        new AdaptiveText()
                        {
                            Text = "Bellevue, WA 98008",
                            HintStyle = AdaptiveTextStyle.CaptionSubtle,
                            HintAlign = AdaptiveTextAlign.Right
                        }
                    }
                }
            }
        }
    }
}
<binding template="ToastGeneric">
    ...
    <group>
        <subgroup>
            <text hint-style="base">52 attendees</text>
            <text hint-style="captionSubtle">23 minute drive</text>
        </subgroup>
        <subgroup>
            <text hint-style="captionSubtle" hint-align="right">1 Microsoft Way</text>
            <text hint-style="captionSubtle" hint-align="right">Bellevue, WA 98008</text>
        </subgroup>
    </group>
</binding>

按鈕Buttons

按鈕讓快顯通知具有互動功能,使用者可以用來對快顯通知採取快速動作,而不會中斷他們目前的工作流程。Buttons make your toast interactive, letting the user take quick actions on your toast notification without interrupting their current workflow. 例如,使用者可以直接從快顯通知中回覆訊息,甚至在沒有開啟電子郵件 App 的情況下刪除電子郵件。For example, users can reply to a message directly from within a toast, or delete an email without even opening the email app. 按鈕顯示在通知的展開部分。Buttons appear in the expanded portion of your notification.

若要深入了解端對端實作按鈕,請參閱傳送本機快顯通知To learn more about implementing buttons end-to-end, see Send local toast.

按鈕可以執行下列其他動作...Buttons can perform the following different actions...

  • 使用可用來瀏覽至特定頁面/內容的引數,在前景啟用應用程式。Activating the app in the foreground, with an argument that can be used to navigate to a specific page/context.
  • 針對快速回覆或類似案例,啟用 App 的背景工作。Activating the app's background task, for a quick-reply or similar scenario.
  • 透過通訊協定啟動來啟用另一個應用程式。Activating another app via protocol launch.
  • 執行系統動作,例如 snoozing 或關閉通知。Performing a system action, such as snoozing or dismissing the notification.

注意

您最多只能有 5 個按鈕 (包括稍後會討論的操作功能表項目)。You can only have up to 5 buttons (including context menu items which we discuss later).

notification with actions, example 1
ToastContent content = new ToastContent()
{
    ...
 
    Actions = new ToastActionsCustom()
    {
        Buttons =
        {
            new ToastButton("See more details", "action=viewdetails&contentId=351")
            {
                ActivationType = ToastActivationType.Foreground
            },

            new ToastButton("Remind me later", "action=remindlater&contentId=351")
            {
                ActivationType = ToastActivationType.Background
            }
        }
    }
};
<toast launch="app-defined-string">

    ...

    <actions>

        <action
            content="See more details"
            arguments="action=viewdetails&amp;contentId=351"
            activationType="foreground"/>

        <action
            content="Remind me later"
            arguments="action=remindlater&amp;contentId=351"
            activationType="background"/>

    </actions>

</toast>

具有圖示的按鈕Buttons with icons

您可以將圖示新增到您的按鈕。You can add icons to your buttons. 這些圖示是白色透明、100% 縮放比例的 16 x 16 像素影像,且影像本身不應包含邊框間距。These icons are white transparent 16x16 pixel images at 100% scaling, and should have no padding included in the image itself. 如果您選擇在快顯通知上提供圖示,您必須為通知中的所有按鈕都提供圖示,因為這會將按鈕樣式轉換為圖示按鈕。If you choose to provide icons on a toast notification, you must provide icons for ALL of your buttons in the notification, as it transforms the style of your buttons into icon buttons.

注意

對於協助工具,請務必包含圖示的高對比白色版本 (白色背景的黑色圖示),以便當使用者開啟 [高對比白色] 模式時,您的圖示可以顯示出來。For accessibility, be sure to include a contrast-white version of the icon (a black icon for white backgrounds), so that when the user turns on High Contrast White mode, your icon is visible. 請至快顯通知協助工具頁面深入了解。Learn more on the toast accessiblity page.

Toast that has buttons with icons
new ToastButton("Dismiss", "dismiss")
{
    ActivationType = ToastActivationType.Background,
    ImageUri = "Assets/ToastButtonIcons/Dismiss.png"
}
<action
    content="Dismiss"
    imageUri="Assets/ToastButtonIcons/Dismiss.png"
    arguments="dismiss"
    activationType="background"/>

具有擱置中更新啟用的按鈕Buttons with pending update activation

Fall Creators Update 的新功能:在背景啟動按鈕上,您可以使用 PendingUpdate 的啟用後行為在快顯通知中建立多步驟互動。New in Fall Creators Update: On background activation buttons, you can use an after activation behavior of PendingUpdate to create multi-step interactions in your toast notifications. 當使用者按下您的按鈕時,便會啟用背景工作,快顯通知將進入「擱置中的更新」狀態,它會停留在螢幕上,直到背景工作使用新的快顯通知來取代快顯通知。When the user clicks your button, your background task is activated, and the toast gets placed in a "pending update" state, where it stays on screen till your background task replaces the toast with a new toast.

若要了解如何執行此程序,請參閱快顯通知擱置中的更新To learn how to implement this, see Toast pending update.

具有擱置更新的快顯通知

內容功能表動作Context menu actions

年度更新版的新功能:您可以新增額外的內容功能表動作至現有的內容功能表 (當使用者以滑鼠右鍵按一下控制中心中的快顯通知,便會顯示此內容功能表)。New in Anniversary Update: You can add additional context menu actions to the existing context menu that appears when the user right clicks your toast from within Action Center. 請注意,只有在控制中心內以滑鼠右鍵按一下時,才會出現這個功能表。Note that this menu only appears when right clicked from Action Center. 以滑鼠右鍵按一下快顯通知快顯橫幅並不會出現此功能表。It does not appear when right clicking a toast popup banner.

注意

在舊款裝置上,這些額外的內容功能表動作會在您的快顯通知上顯示為一般按鈕。On older devices, these additional context menu actions will simply appear as normal buttons on your toast.

您新增的其他內容功能表動作(例如「變更位置」)會出現在兩個預設系統專案的上方。The additional context menu actions you add (such as "Change location") appear above the two default system entries.

Toast with context menu
ToastContent content = new ToastContent()
{
    ...
 
    Actions = new ToastActionsCustom()
    {
        ContextMenuItems =
        {
            new ToastContextMenuItem("Change location", "action=changeLocation")
        }
    }
};
<toast>

    ...

    <actions>

        <action
            placement="contextMenu"
            content="Change location"
            arguments="action=changeLocation"/>

    </actions>

</toast>

注意

額外內容功能表項目計入快顯通知上的 5 個按鈕總限制。Additional context menu items contribute to the total limit of 5 buttons on a toast.

額外內容功能表項目的啟用處理方式與快顯通知按鈕相同。Activation of additional context menu items is handled identical to toast buttons.

輸入Inputs

輸入是在快顯通知的 [動作] 區域中指定,也就是只有在展開快顯通知時才能看得到。Inputs are specified within the Actions region of the toast region of the toast, meaning they are only visible when the toast is expanded.

快速回覆文字方塊Quick reply text box

若要啟用 [快速回復] 文字方塊(例如,在訊息應用程式中),請加入文字輸入和按鈕,並參考文字輸入欄位的識別碼,讓按鈕顯示在輸入欄位旁。To enable a quick reply text box (for example, in a messaging app) add a text input and a button, and reference the ID of the text input field so that the button is displayed next to to the input field. 按鈕的圖示應該是32x32 圖元影像,其中沒有填補、白色圖元設定為透明,以及100% 縮放比例。The icon for the button should be a 32x32 pixel image with no padding, white pixels set to transparent, and 100% scale.

notification with text input and actions
ToastContent content = new ToastContent()
{
    ...
 
    Actions = new ToastActionsCustom()
    {
        Inputs =
        {
            new ToastTextBox("tbReply")
            {
                PlaceholderContent = "Type a reply"
            }
        },

        Buttons =
        {
            new ToastButton("Reply", "action=reply&convId=9318")
            {
                ActivationType = ToastActivationType.Background,

                // To place the button next to the text box,
                // reference the text box's Id and provide an image
                TextBoxId = "tbReply",
                ImageUri = "Assets/Reply.png"
            }
        }
    }
};
<toast launch="app-defined-string">

    ...

    <actions>

        <input id="textBox" type="text" placeHolderContent="Type a reply"/>

        <action
            content="Send"
            arguments="action=reply&amp;convId=9318"
            activationType="background"
            hint-inputId="textBox"
            imageUri="Assets/Reply.png"/>

    </actions>

</toast>

使用按鈕列的輸入Inputs with buttons bar

您也可以讓一個 (或多個) 輸入與一般按鈕一起顯示在輸入下方。You also can have one (or many) inputs with normal buttons displayed below the inputs.

notification with text and input actions
ToastContent content = new ToastContent()
{
    ...
 
    Actions = new ToastActionsCustom()
    {
        Inputs =
        {
            new ToastTextBox("tbReply")
            {
                PlaceholderContent = "Type a reply"
            }
        },

        Buttons =
        {
            new ToastButton("Reply", "action=reply&threadId=9218")
            {
                ActivationType = ToastActivationType.Background
            },

            new ToastButton("Video call", "action=videocall&threadId=9218")
            {
                ActivationType = ToastActivationType.Foreground
            }
        }
    }
};
<toast launch="app-defined-string">

    ...

    <actions>

        <input id="textBox" type="text" placeHolderContent="Type a reply"/>

        <action
            content="Reply"
            arguments="action=reply&amp;threadId=9218"
            activationType="background"/>

        <action
            content="Video call"
            arguments="action=videocall&amp;threadId=9218"
            activationType="foreground"/>

    </actions>

</toast>

選取輸入Selection input

除了文字方塊之外,您還可以使用選取功能表。In addition to text boxes, you can also use a selection menu.

notification with selection input and actions
ToastContent content = new ToastContent()
{
    ...
 
    Actions = new ToastActionsCustom()
    {
        Inputs =
        {
            new ToastSelectionBox("time")
            {
                DefaultSelectionBoxItemId = "lunch",
                Items =
                {
                    new ToastSelectionBoxItem("breakfast", "Breakfast"),
                    new ToastSelectionBoxItem("lunch", "Lunch"),
                    new ToastSelectionBoxItem("dinner", "Dinner")
                }
            }
        },

        Buttons = { ... }
};
<toast launch="app-defined-string">

    ...

    <actions>

        <input id="time" type="selection" defaultInput="lunch">
            <selection id="breakfast" content="Breakfast" />
            <selection id="lunch" content="Lunch" />
            <selection id="dinner" content="Dinner" />
        </input>

        ...

    </actions>

</toast>

延遲/關閉Snooze/dismiss

我們可以使用選取功能表,建立採用系統延遲及關閉動作的提醒通知。Using a selection menu and two buttons, we can create a reminder notification that utilizes the system snooze and dismiss actions. 請務必將案例設定為 Reminder,才能讓通知的行為表現得像提醒。Make sure to set the scenario to Reminder for the notification to behave like a reminder.

reminder notification

我們在快顯通知按鈕上使用 SelectionBoxId 屬性,將 [延遲] 按鈕連結至選項功能表輸入。We link the Snooze button to the selection menu input using the SelectionBoxId property on the toast button.

ToastContent content = new ToastContent()
{
    Scenario = ToastScenario.Reminder,

    ...
 
    Actions = new ToastActionsCustom()
    {
        Inputs =
        {
            new ToastSelectionBox("snoozeTime")
            {
                DefaultSelectionBoxItemId = "15",
                Items =
                {
                    new ToastSelectionBoxItem("5", "5 minutes"),
                    new ToastSelectionBoxItem("15", "15 minutes"),
                    new ToastSelectionBoxItem("60", "1 hour"),
                    new ToastSelectionBoxItem("240", "4 hours"),
                    new ToastSelectionBoxItem("1440", "1 day")
                }
            }
        },

        Buttons =
        {
            new ToastButtonSnooze()
            {
                SelectionBoxId = "snoozeTime"
            },
 
            new ToastButtonDismiss()
        }
    }
};
<toast scenario="reminder" launch="action=viewEvent&amp;eventId=1983">
   
  ...
 
  <actions>
     
    <input id="snoozeTime" type="selection" defaultInput="15">
      <selection id="1" content="1 minute"/>
      <selection id="15" content="15 minutes"/>
      <selection id="60" content="1 hour"/>
      <selection id="240" content="4 hours"/>
      <selection id="1440" content="1 day"/>
    </input>
 
    <action activationType="system" arguments="snooze" hint-inputId="snoozeTime" content="" />
 
    <action activationType="system" arguments="dismiss" content=""/>
     
  </actions>
   
</toast>

若要使用系統延遲和關閉動作:To use the system snooze and dismiss actions:

  • 指定 ToastButtonSnoozeToastButtonDismissSpecify a ToastButtonSnooze or ToastButtonDismiss
  • 選擇性指定自訂內容字串:Optionally specify a custom content string:
    • 如果沒有提供字串,我們會自動使用 "Snooze" (延遲) 和 "Dismiss" (關閉) 的當地語系化字串。If you don't provide a string, we'll automatically use localized strings for "Snooze" and "Dismiss".
  • 選擇性指定 SelectionBoxIdOptionally specify the SelectionBoxId:
    • 如果您不想讓使用者選取延遲間隔,而只想讓您的通知延遲一段系統定義的時間間隔 (整個系統一致),那就不要建置任何 <input>。If you don't want the user to select a snooze interval and instead just want your notification to snooze only once for a system-defined time interval (that is consistent across the OS), then don't construct any <input> at all.
    • 如果您想要提供延遲間隔選取項目:If you want to provide snooze interval selections:
      • 在延遲動作中指定 SelectionBoxIdSpecify SelectionBoxId in the snooze action
      • 將輸入的 id 與延遲動作的 SelectionBoxId 比對Match the id of the input with the SelectionBoxId of the snooze action
      • ToastSelectionBoxItem 的值指定為 nonNegativeInteger,這表示以分鐘為單位的延遲間隔。Specify ToastSelectionBoxItem's value to be a nonNegativeInteger which represents snooze interval in minutes.

音效Audio

自訂音訊一直以來都支援行動裝置,也支援桌上型電腦版本 1511 (組建 10586) 或較新版本。Custom audio has always been supported by Mobile, and is supported in Desktop Version 1511 (build 10586) or newer. 您可以透過下列方式參考自訂音訊︰Custom audio can be referenced via the following paths:

  • ms-appx:///ms-appx:///
  • ms-appdata:///ms-appdata:///

或者,您可以從 ms-winsoundevents 清單 (英文) 中挑選,該清單中的項目支援這兩個平台。Alternatively, you can pick from the list of ms-winsoundevents, which have always been supported on both platforms.

ToastContent content = new ToastContent()
{
    ...

    Audio = new ToastAudio()
    {
        Src = new Uri("ms-appx:///Assets/NewMessage.mp3")
    }
}
<toast launch="app-defined-string">

    ...

    <audio src="ms-appx:///Assets/NewMessage.mp3"/>

</toast>

如需快顯通知中音訊的相關資訊,請參閱音訊結構頁面 (英文)。See the audio schema page for information on audio in toast notifications. 如需了解如何使用自訂音效傳送快顯通知,請參閱自訂快顯通知的音效To learn how to send a toast using custom audio, see custom audio on toasts.

鬧鐘、提醒及來電Alarms, reminders, and incoming calls

若要建立鬧鐘、提醒和來電通知,只需使用一般快顯通知並指派其案例值即可。To create alarms, reminders, and incoming call notifications, you simply use a normal toast notification with a scenario value assigned to it. 案例會調整一些行為,以便建立一致且整合的使用者體驗。The scenario adusts a few behaviors to create a consistent and unified user experience.

重要

使用提醒或鬧鐘時,您必須在您的快顯通知上至少提供一個按鈕。When using Reminder or Alarm, you must provide at least one button on your toast notification. 否則,快顯通知會被視為一般的快顯通知。Otherwise, the toast will be treated as a normal toast.

  • Reminder:提醒快顯通知將停留在螢幕上,直到使用者將它關閉或採取動作。Reminder: The notification will stay on screen until the user dismisses it or takes action. 在 Windows Mobile 上,快顯通知也會以預先展開的方式顯示。On Windows Mobile, the toast will also show pre-expanded. 將會播放提醒音效。A reminder sound will be played.
  • Alarm:除了提醒行為之外,鬧鐘還會另外使用預設鬧鐘音效,循環重複播放音效。Alarm: In addition to the reminder behaviors, alarms will additionally loop audio with a default alarm sound.
  • IncomingCall:來電通知會在 Windows Mobile 裝置上以全螢幕方式顯示。IncomingCall: Incoming call notifications are displayed full screen on Windows Mobile devices. 否則,除了使用鈴聲音效以外,其行為與鬧鐘相同,其按鈕也會以不同方式設定樣式。Otherwise, they have the same behaviors as alarms except they use ringtone audio and their buttons are styled differently.
ToastContent content = new ToastContent()
{
    Scenario = ToastScenario.Reminder,

    ...
}
<toast scenario="reminder" launch="app-defined-string">

    ...

</toast>

當地語系化和協助工具Localization and accessibility

您的磚和快顯通知可以載入針對顯示語言、顯示縮放比例、高對比及其他執行階段內容量身打造的字串與影像。Your tiles and toasts can load strings and images tailored for display language, display scale factor, high contrast, and other runtime contexts. 如需詳細資訊,請參閱對語言、縮放比例及高對比的磚與快顯通知支援For more info, see Tile and toast notification support for language, scale, and high contrast.

處理啟用Handling activation

如需了解如何處理快顯通知啟用 (使用者按一下您的快顯通知或快顯通知上的按鈕),請參閱傳送本機快顯通知To learn how to handle toast activations (the user clicking your toast or buttons on the toast), see Send local toast.