toast 内容Toast content

借助自适应和交互式 toast 通知,可使用文本、图像和按钮/输入创建灵活的通知。Adaptive and interactive toast notifications let you create flexible notifications with text, images, and buttons/inputs.

重要 APIUWP 社区工具包通知 NuGet 程序包Important APIs: UWP Community Toolkit Notifications nuget package

备注

若要查看 Windows8.1 和 Windows Phone 8.1 中的传统模板,请参阅传统 toast 模板目录To see the legacy templates from Windows8.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 应用通过在你编辑时提供 toast 的即时可视预览来帮助你设计交互 toast 通知,类似于 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.

发送 toast 通知Sending a toast notification

要了解如何发送通知,请参阅发送本地 ToastTo learn how to send a notification, see Send local toast. 本文档仅介绍如何创建 Toast 内容。This documentation only covers creating the toast content.

Toast 通知结构Toast notification structure

Toast 通知是某些数据属性(如标记/组,用于标识通知)与 Toast 内容的组合。Toast notifications are a combination of some data properties like Tag/Group (which let you identify the notification) and the toast content.

Toast 内容的核心组件有The core components of toast content are...

  • launch:定义当用户单击你的 Toast 时将传回应用的参数,允许你深层链接到 Toast 所显示的正确内容。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. 有关详细信息,请参阅发送本地 ToastTo learn more, see Send local toast.
  • visual:toast 的可视部分,包括带有文本和图像的通用绑定。visual: The visual portion of the toast, including the generic binding that contains text and images.
  • actions:toast 的交互部分,包括输入和操作。actions: The interactive portion of the toast, including inputs and actions.
  • audio:控制向用户显示 Toast 时播放的音频。audio: Controls the audio played when the toast is shown to the user.

Toast 内容在原始 XML 中定义,但你可以使用我们的 NuGet 库获取 C#(或 C++)对象模型来构造 Toast 内容。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. 本文介绍了 Toast 内容中的所有内容。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>

下面是 Toast 内容的可视化表示形式:Here is a visual representation of the toast's content:

Toast 通知结构

VisualVisual

每个 toast 均必须指定一个 visual,此处必须包含带文本、图像等的通用 toast 绑定。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.

关于 Toast 通知的应用标识通过手机应用图标传达。Your app's identity on the toast notification is conveyed via your app icon. 但是,如果使用应用徽标替代,文本行下面将显示应用名称。However, if you use the app logo override, we will display your app name beneath your lines of text.

正常 toast 的应用标识App identity for normal toast 带有 appLogoOverride 的应用标识App identity with appLogoOverride
notification without appLogoOverride notification with appLogoOverride

文本元素Text elements

每个 toast 均必须具有至少一个文本元素,此外还可包含两个文本元素,类型均为 AdaptiveTextEach 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 logo override

默认情况下,toast 将显示应用徽标。By default, your toast will display your app's logo. 但可将此徽标替代为自己的 ToastGenericAppLogo 图像。However, you can override this logo with your own ToastGenericAppLogo image. 例如,如果这是来自某人的通知,则建议将应用徽标替换为此人的照片。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

周年更新的新增功能:toast 可显示主图,这是在 toast 横幅中以及在操作中心时突出显示的特别 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

可提供在展开 toast 时显示的全宽内联图像。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

Toast 通知中使用的图像可源自以下位置...The images you use in your toast notification can be sourced from...

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

对于 http 和 https 远程 Web 图像,每个单独图像的文件大小存在一定限制。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

创建者更新中的新增功能:现在,你可以用自己的准确表示消息/信息/内容生成时间的时间戳替代系统提供的时间戳。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

若要详细了解如何使用自定义时间戳,请参阅 toast 上的自定义时间戳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

创意者更新的新增功能:可在 Toast 通知中提供进度栏,让用户时刻了解操作进度,例如下载进度。New in Creators Update: You can provide a progress bar on your toast notification to keep the user informed of the progress of operations, like downloads and more.

Toast with progress bar

若要详细了解如何使用进度栏,请参阅 Toast 进度栏To learn more about using a progress bar, please see Toast progress bar.

标题Headers

创意者更新的新增功能:可在操作中心将通知分到不同的标题下。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

若要详细了解如何使用标题,请参阅 Toast 标题To learn more about using headers, please see Toast headers.

自适应内容Adaptive content

周年更新中的新增功能:除了上面指定的内容外,你还可以显示在展开 Toast 时可见的附加自适应内容。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. 否则将不会使用自适应呈现。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

按钮使你的 Toast 可交互,让用户无需中断其当前工作流即可就你的 Toast 通知采取快速操作。Buttons make your toast interactive, letting the user take quick actions on your toast notification without interrupting their current workflow. 例如,用户可以直接从 Toast 内回复邮件,甚至在不打开电子邮件应用的情况下删除电子邮件。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.

若要详细了解如何端到端操控按钮,请参阅发送本地 ToastTo 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.
  • 激活应用的后台任务以便快速回复或类似的场景。Activating the app's background task, for a quick-reply or similar scenario.
  • 通过协议启动激活另一个应用。Activating another app via protocol launch.
  • 执行系统操作,如推迟或取消通知。Performing a system action, like 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% 缩放时为白色透明的 16x16 像素图像,且图像本身不应包含任何填充。These icons are white transparent 16x16 pixel images at 100% scaling, and should have no padding included in the image itself. 如果选择在一条 Toast 通知上提供图标,则必须为该通知中的所有按钮提供图标,因为该操作会将按钮样式转换为图标按钮。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. 有关详细信息,请参阅 Toast 辅助功能页面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 的激活后行为在 Toast 通知中创建多步骤的交互。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. 用户单击按钮后,将激活后台任务,此时 Toast 处于“等待更新”状态。该状态下,屏幕上始终显示 Toast,直到后台任务将其替换为新的 Toast。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.

若要了解如何实现此操作,请参阅 Toast 等待更新To learn how to implement this, see Toast pending update.

有待更新的 Toast

关联菜单操作Context menu actions

周年更新的新增功能:可向现有关联菜单(用户从操作中心右键单击 Toast 时会出现)添加其他关联菜单。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. 右键单击 Toast 弹出式横幅时,该菜单不会出现。It does not appear when right clicking a toast popup banner.

备注

在较旧的设备上,上述其他关联菜单操作仅显示为 Toast 上的正常按钮。On older devices, these additional context menu actions will simply appear as normal buttons on your toast.

添加的其他关联菜单操作(如“更改位置”)显示在两个默认系统项的上方。The additional context menu actions you add (like "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>

备注

其他关联菜单项计入 Toast 按钮(数量上限为 5 个)。Additional context menu items contribute to the total limit of 5 buttons on a toast.

其他关联菜单项的激活方式与 Toast 按钮的相同。Activation of additional context menu items is handled identical to toast buttons.

输入Inputs

输入是在 toast 的 toast 区域的 actions 区域中指定的,这表示它们仅在 toast 展开时可见。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

要启用快速回复文本框,例如在消息传递方案中,请添加文本输入和按钮,并引用文本输入的 ID 以使按钮显示在输入旁。To enable a quick reply text box, like for a messaging scenario, add a text input and a button, and reference the text input's id so that the button is displayed adjacent to the input.

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. 请确保将方案设置为“提醒”以便通知像提醒那样工作。Make sure to set the scenario to Reminder for the notification to behave like a reminder.

reminder notification

我们使用 toast 按钮的 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:
    • 如果你不提供字符串,我们将自动使用“推迟”和“消除”的本地化字符串。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>

若要了解 toast 通知中的音频,请参阅音频架构页面See the audio schema page for information on audio in toast notifications. 若要了解如何使用自定义音频发送 toast,请参阅 toast 中的自定义音频To learn how to send a toast using custom audio, see custom audio on toasts.

闹钟、提醒和来电Alarms, reminders, and incoming calls

要创建闹钟、提醒和来电通知,只需使用正常的 Toast 通知并为它分配一个方案值。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.

重要

使用提醒或闹钟时,必须在 Toast 通知上提供至少一个按钮。When using Reminder or Alarm, you must provide at least one button on your toast notification. 否则,该 Toast 将被视为正常 Toast。Otherwise, the toast will be treated as a normal toast.

  • 提醒:通知将保留在屏幕上,直到用户消除它或采取操作。Reminder: The notification will stay on screen until the user dismisses it or takes action. 在 Windows 移动版上,该 Toast 还会以预先展开的形式显示。On Windows Mobile, the toast will also show pre-expanded. 将播放提醒声音。A reminder sound will be played.
  • 闹钟:除提醒行为外,闹钟将用默认的闹钟声音自动循环音频。Alarm: In addition to the reminder behaviors, alarms will additionally loop audio with a default alarm sound.
  • 来电:来电通知在 Windows 移动设备上全屏显示。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

磁贴和 toast 可加载为显示语言、显示比例系数、高对比度和其他运行时上下文定制的字符串和图像。Your tiles and toasts can load strings and images tailored for display language, display scale factor, high contrast, and other runtime contexts. 有关详细信息,请参阅磁贴和 toast 通知的语言、比例和高对比度支持For more info, see Tile and toast notification support for language, scale, and high contrast.

处理激活Handling activation

要了解如何处理 Toast 激活(用户单击你的 Toast 或 Toast 上的按钮),请参阅发送本地 ToastTo learn how to handle toast activations (the user clicking your toast or buttons on the toast), see Send local toast.