description | title | ms.assetid | label | template | ms.date | ms.topic | keywords | ms.localizationpriority |
---|---|---|---|---|---|---|---|---|
This article describes the UI elements that can be used in an app notification and provides code examples for generating the XML format for an app notification. | App notification content | 1FCE66AF-34B4-436A-9FC9-D0CF4BDA5A01 | App notification content | detail.hbs | 11/14/2022 | article | windows 10, uwp, toast notifications, interactive toasts, adaptive toasts, toast content, toast payload, app notifications | medium |
App notifications are flexible notifications with text, images, and buttons/inputs. This article describes the UI elements that can be used in an app notification and provides code examples for generating the XML format for an app notification.
Note
The term "toast notification" is being replaced with "app notification". These terms both refer to the same feature of Windows, but over time we will phase out the use of "toast notification" in the documentation.
App notifications are defined with an XML payload which is defined by the App notification schema. Currently, there are three ways of generating the XML payload fo an app notification. The code examples in this article demonstrate all three methods:
- The Microsoft.Windows.AppNotifications.Builder APIs - Introduced in Windows App SDK 1.2, this namespace provides APIs that allow you to easily build the XML payload for a notification programmatically without having to worry about the specifics of the XML format. Code examples using these APIs are in the tabs labeled "Windows App SDK".
- The
Microsoft.Toolkit.Uwp.Notifications
builder syntax - These APIs are part of the UWP Community Toolkit and provides support for UWP apps. Although these APIs can also be used for Windows App SDK apps, and continue to be supported, we recommend that new implementations use the Microsoft.Windows.AppNotifications.Builder APIs. To use Community Toolkit APIs, add the UWP Community Toolkit Notifications nuget package to your project. The C# samples provided in this article use version 7.0.0 of the NuGet package. Code examples using these APIs are in the tabs labeled "Windows Community Toolkit". - Raw XML - If you prefer, you can create your own custom code to generate XML strings in the required format. The raw XML examples are in the tabs labeled "XML".
Install Notifications Visualizer. This free Windows app helps you design interactive app notifications by providing an instant visual preview of your toast as you edit it, similar to Visual Studio's XAML editor/design view. See Notifications Visualizer for more information, or download Notifications Visualizer from the Store.
This article only covers creating the app notification content. For information on sending a notification after you have generated the XML payload, see Send a local app notification.
Some important, high-level components of an app notification XML payload include:
- toast: The launch attribute of this element 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 a local app notification.
- visual: This element represents visual portion of the toast, including the generic binding that contains text and images.
- actions: This element represents interactive portion of the toast, including inputs and actions.
- audio: This element specifies the audio played when the toast is shown to the user.
varbuilder=newAppNotificationBuilder().AddArgument("conversationId","9813").AddText("Some text").AddButton(newAppNotificationButton("Archive").AddArgument("action","archive")).SetAudioUri(newUri("ms-appx:///Sound.mp3"));
varbuilder=newToastContentBuilder().AddArgument("conversationId",9813).AddText("Some text").AddButton(newToastButton().SetContent("Archive").AddArgument("action","archive")).AddAudio(newUri("ms-appx:///Audio/NotificationSound.mp3"));
<toastlaunch='conversationId=9813'> <visual> <bindingtemplate='ToastGeneric'> <text>Some text</text> </binding> </visual> <audiosrc='ms-appx:///Audio/NotificationSound.mp3'/> <actions> <actioncontent='Archive'arguments='action=archive'/> </actions> </toast>
Here is a visual representation of the app notification's content:
The attribution area is at the top of the app notification. Starting with Windows 11, your app's name and icon are displayed in this area. The attribution area also includes a close button that allows the user to quickly dismiss the notification and an ellipses menu that allows the user to quickly disable notifications for your app or go to the Windows Settings page for your app's notifications. The attribution area is configured by the shell and can't be overridden in the toast XML payload, although your app can add items to the attribution area context menu. For more information see Context menu actions.
Each app notification must specify a visual element, where you must provide a generic toast binding and which can contain text and images. 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 App notification schema.
Each app notification must have at least one text element, and can contain two additional text elements, all of type AdaptiveText.
Since the Windows 10 Anniversary Update, you can control how many lines of text are displayed by using the HintMaxLines property on the text. 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).
varbuilder=newAppNotificationBuilder().AddArgument("conversationId",9813).AddText("Adaptive Tiles Meeting",newAppNotificationTextProperties().SetMaxLines(1)).AddText("Conf Room 2001 / Building 135").AddText("10:00 AM - 10:30 AM");
varbuilder=newToastContentBuilder().AddArgument("meetingId",9813).AddText("Adaptive Tiles Meeting",hintMaxLines:1).AddText("Conf Room 2001 / Building 135").AddText("10:00 AM - 10:30 AM");
<toastlaunch='meetingId=9813'> <visual> <bindingtemplate='ToastGeneric'> <texthint-maxLines='1'>Adaptive Tiles Meeting</text> <text>Conf Room 2001 / Building 135</text> <text>10:00 AM - 10:30 AM</text> </binding> </visual> </toast>
By default, images are displayed inline, after any text elements, filling the full width of the visual area.
varbuilder=newAppNotificationBuilder().AddText("Featured image of the day.").SetInlineImage(newUri("ms-appx:///Images/InlineImage.png"));AppNotificationManager.Default.Show(builder.BuildNotification());
varbuilder=newToastContentBuilder().AddText("Featured image of the day.").AddInlineImage(newUri("ms-appx:///Images/InlineImage.png"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Featured image of the day.</text> <imagesrc='ms-appx:///Images/InlineImage.png'/> </binding> </visual> </toast>
Specifying a placement value of "appLogoOverride" will cause the image to be displayed in a square on the left side of the visual area. The name of this property reflects the behavior in previous versions of Windows, where the image would replace the default app logo image. In Windows 11, the app logo is displayed in the attribution area, so it is not overridden by the appLogoOverride image placement.
Image dimensions are 48x48 pixels at 100% scaling. We generally recommend providing a version each icon asset for each scale factor: 100%, 125%, 150%, 200%, and 400%.
varbuilder=newAppNotificationBuilder().AddText("Featured image of the day.").SetAppLogoOverride(newUri("ms-appx:///Images/AppLogo.png"));
varbuilder=newToastContentBuilder().AddText("Featured image of the day.").AddAppLogoOverride(newUri("ms-appx:///Images/AppLogo.png"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Featured image of the day.</text> <imageplacement='appLogoOverride'src='ms-appx:///Images/AppLogo.png'/> </binding> </visual> </toast>
Microsoft style guidelines recommend representing profile pictures with a circular image to provide a consistent representation of people across apps and the shell. Set the HintCrop property to Circle to render the image with a circular crop.
varbuilder=newAppNotificationBuilder().AddText("Matt sent you a friend request").AddText("Hey, wanna dress up as wizards and ride around on hoverboards?").SetAppLogoOverride(newUri("ms-appx:///Images/Profile.png"),AppNotificationImageCrop.Circle);
varbuilder=newToastContentBuilder().AddText("Matt sent you a friend request").AddText("Hey, wanna dress up as wizards and ride around on hoverboards?").AddAppLogoOverride(newUri("ms-appx:///Images/Profile.png"),ToastGenericAppLogoCrop.Circle);
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Matt sent you a friend request</text> <text>Hey, wanna dress up as wizards and ride around on hoverboards?</text> <imageplacement='appLogoOverride'src='ms-appx:///Images/Profile.png'hint-crop='circle'/> </binding> </visual> </toast>
New in Anniversary Update: App notifications can display a hero image, which is a featured ToastGenericHeroImage displayed prominently within the toast banner and while inside Notification Center. Image dimensions are 364x180 pixels at 100% scaling.
varbuilder=newAppNotificationBuilder().AddText("Marry Anne").AddText("Check out where we camped last night!").SetHeroImage(newUri("ms-appx:///Images/HeroImage.png"));
newToastContentBuilder().AddText("Marry Anne").AddText("Check out where we camped last night!").AddHeroImage(newUri("ms-appx:///Images/HeroImage.png"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Mary Anne</text> <text>Check out where we camped last night!</text> <imageplacement='hero'src='ms-appx:///Images/HeroImage.png'/> </binding> </visual> </toast>
The images you use in your toast notification can be sourced from...
- http://
- ms-appx:///
- ms-appdata:///
For http and https remote web images, there are limits on the file size of each individual image. In the Fall Creators Update (16299), we increased the limit to be 3 MB on normal connections and 1 MB on metered connections. Before that, images were always limited to 200 KB.
Normal connection | Metered connection | Before Fall Creators Update |
---|---|---|
3 MB | 1 MB | 200 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.
New in Anniversary Update: If you need to reference the source of your content, you can use attribution text. This text is always displayed below any text elements, but above inline images. The text uses a slightly smaller size than standard text elements to help to distinguish from regular text elements.
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).
varbuilder=newAppNotificationBuilder().AddText("Marry Anne").AddText("Check out where we camped last night!").SetAttributionText("via SMS");.SetHeroImage(newUri("ms-appx:///Images/HeroImage.png"));
newToastContentBuilder().AddText("Marry Anne").AddText("Check out where we camped last night!").AddAttributionText("Via SMS");.AddHeroImage(newUri("ms-appx:///Images/HeroImage.png"));
<toast> <visual> <bindingtemplate="ToastGeneric"> <imagesrc="ms-appx:///Images/HeroImage.png"/> <text>Mary Anne</text> <text>Check out where we camped last night!</text> <textplacement="attribution">Via SMS</text> </binding> </visual> </toast>
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 Notification Center.
To learn more about using a custom timestamp, please see custom timestamps on toasts.
varbuilder=newAppNotificationBuilder().AddText("Matt sent you a friend request").AddText("Hey, wanna dress up as wizards and ride around on hoverboards?").SetTimeStamp(newDateTime(2017,04,15,19,45,00,DateTimeKind.Utc));
varbuilder=newToastContentBuilder().AddText("Matt sent you a friend request").AddText("Hey, wanna dress up as wizards and ride around on hoverboards?").AddCustomTimeStamp(newDateTime(2017,04,15,19,45,00,DateTimeKind.Utc));
<toastdisplayTimestamp='2017-04-15T12:45:00-07:00'> <visual> <bindingtemplate='ToastGeneric'> <text>Matt sent you a friend request</text> <text>Hey, wanna dress up as wizards and ride around on hoverboards?</text> </binding> </visual> </toast>
New in Creators Update: You can provide a progress bar on your app notification to keep the user informed of the progress of operations such as downloads.
To learn more about using a progress bar, please see Toast progress bar.
New in Creators Update: You can group notifications under headers within Notification 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.
To learn more about using headers, please see Toast headers.
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.
This additional content is specified using Adaptive, which you can learn more about by reading the Adaptive Tiles documentation.
Note that any adaptive content must be contained within an AdaptiveGroup. Otherwise it will not be rendered using adaptive.
Here's an example where columns and some advanced adaptive text elements are used. Since the text elements are within an AdaptiveGroup, they support all the rich adaptive styling properties.
// The Microsoft.Windows.AppNotifications.Builder syntax does not currently support adaptive text elements.
newToastContentBuilder() ....AddVisualChild(newAdaptiveGroup(){Children={newAdaptiveSubgroup(){Children={newAdaptiveText(){Text="52 attendees",HintStyle=AdaptiveTextStyle.Base},newAdaptiveText(){Text="23 minute drive",HintStyle=AdaptiveTextStyle.CaptionSubtle}}},newAdaptiveSubgroup(){Children={newAdaptiveText(){Text="1 Microsoft Way",HintStyle=AdaptiveTextStyle.CaptionSubtle,HintAlign=AdaptiveTextAlign.Right},newAdaptiveText(){Text="Bellevue, WA 98008",HintStyle=AdaptiveTextStyle.CaptionSubtle,HintAlign=AdaptiveTextAlign.Right}}}}});
<toastlaunch="app-defined-string"> <visual> <bindingtemplate="ToastGeneric"> <text>Reminder: Windows Launch Party</text> <text>4:00 PM, 10/21/2021</text> <group> <subgroup> <texthint-style="base">52 attendees</text> <texthint-style="captionSubtle">23 minute drive</text> </subgroup> <subgroup> <texthint-style="captionSubtle"hint-align="right">1 Microsoft Way</text> <texthint-style="captionSubtle"hint-align="right">Bellevue, WA 98008</text> </subgroup> </group> </binding> </visual> </toast>
Buttons make your toast interactive, letting the user take quick actions on your app notification without interrupting their current workflow. 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 activate an app in the following ways:
- The app is activated in the foreground, with an argument that can be used to navigate to a specific page/context.
- Another app is activated via protocol launch.
- Background activation is supported explicitly for UWP apps. For Windows App SDK apps, the app is always launched in the foreground. The app can call AppInstance.GetActivatedEventArgs to detect if the activation was launched by a notification and determine from the passed arguments whether to fully launch the foreground app or just handle the notification and exit.
- System actions, such as snoozing or dismissing the notification, are supported both for UWP apps and for Windows App SDK. The AppNotificationBuilder APIs don't support this scenario but Windows App SDK apps can implement this scenario using the Microsoft.Windows.AppNotifications.Builder APIs or raw XML.
Note
You can only have up to 5 buttons (including context menu items which we discuss later).
newToastContentBuilder()varbuilder=newAppNotificationBuilder().AddText("New product in stock!").AddButton(newAppNotificationButton("See more details").AddArgument("action","viewDetails")).AddArgument("contentId","351").AddButton(newAppNotificationButton("Remind me later").AddArgument("action","remindLater")).AddArgument("contentId","351");
varbuilder=newToastContentBuilder().AddText("New product in stock!").AddButton(newToastButton().SetContent("See more details").AddArgument("action","viewDetails")).AddButton(newToastButton().SetContent("Remind me later").AddArgument("action","remindLater"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>New product in stock!</text> </binding> </visual> <actions> <actioncontent='See more details'arguments='action=viewDetails;contentId=351'/> <actioncontent='Remind me later'arguments='action=remindLater;contentId=351'/> </actions> </toast>
You can add icons to your buttons. 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.
Note
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. For more information, see Tile and toast notification support for language, scale, and high contrast.
newToastContentBuilder()varbuilder=newAppNotificationBuilder().AddText("Return books to the library.").AddButton(newAppNotificationButton("Accept").AddArgument("action","accept").SetIcon(newUri("ms-appx:///Images/Accept.png"))).AddButton(newAppNotificationButton("Snooze").AddArgument("action","snooze").SetIcon(newUri("ms-appx:///Images/Snooze.png"))).AddButton(newAppNotificationButton("Dismiss").AddArgument("action","dismiss").SetIcon(newUri("ms-appx:///Images/Dismiss.png")));
varbuilder=newToastContentBuilder().AddText("New product in stock!").AddButton(newToastButton().SetContent("Accept").AddArgument("action","accept").SetImageUri(newUri("ms-appx:///Images/Accept.png"))).AddButton(newToastButton().SetContent("Snooze").AddArgument("action","snooze").SetImageUri(newUri("ms-appx:///Images/Snooze.png"))).AddButton(newToastButton().SetContent("Dismiss").AddArgument("action","dismiss").SetImageUri(newUri("ms-appx:///Images/Dismiss.png")));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Return books to the library.</text> </binding> </visual> <actions> <actioncontent='Accept'arguments='action=accept'imageUri='ms-appx:///Assets/Accept.png'/> <actioncontent='Snooze'arguments='action=snooze'imageUri='ms-appx:///Assets/Snooze.png'/> <actioncontent='Dismiss'arguments='action=dismiss'imageUri='ms-appx:///Assets/Dismiss.png'/> </actions> </toast>
New in Windows 11 Update: You can add tooltips to your icons with the HintToolTip property in XML. This is ideal if your buttons have icons but no content, as this will make sure you can pass text that Windows Narrator can read. However, if content is present, then Narrator will read the content, no matter what is passed in the tooltip.
varbutton=newAppNotificationButton("Reply").AddArgument("action","reply");if(AppNotificationButton.IsToolTipSupported()){button.ToolTip="Click to reply.";}varbuilder=newAppNotificationBuilder().AddText("Notification text.").AddButton(button);
// The Community Toolkit builder syntax does not currently support icon tooltips.
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Notification text.</text> </binding> </visual> <actions> <actioncontent='Reply'arguments='action=reply'hint-toolTip='Click to reply'/> </actions> </toast>
New in Windows 11 Update: You can add red or green colors to your buttons by adding the useButtonStyle attribute to the toast XML element and the hint-buttonStyle attribute to the action XML element as seen below.
varbuilder=newAppNotificationBuilder().SetScenario(AppNotificationScenario.IncomingCall).AddText("Andrew Bares",newAppNotificationTextProperties().SetIncomingCallAlignment()).AddText("Incoming Call - Mobile",newAppNotificationTextProperties().SetIncomingCallAlignment()).SetInlineImage(newUri("ms-appx:///Images/Profile.png"),AppNotificationImageCrop.Circle).AddButton(newAppNotificationButton().SetToolTip("Answer Video Call").SetButtonStyle(AppNotificationButtonStyle.Success).SetIcon(newUri("ms-appx:///Images/Video.png")).AddArgument("videoId","123")).AddButton(newAppNotificationButton().SetToolTip("Answer Phone Call").SetButtonStyle(AppNotificationButtonStyle.Success).SetIcon(newUri("ms-appx:///Images/Call.png")).AddArgument("callId","123")).AddButton(newAppNotificationButton().SetToolTip("Hang Up").SetButtonStyle(AppNotificationButtonStyle.Critical).SetIcon(newUri("ms-appx:///Images/HangUp.png")).AddArgument("hangUpId","123"));
// The WIndows Community Toolkit builder syntax does not currently support red and green button colors.
<toastscenario='incomingCall'useButtonStyle='true'> <visual> <bindingtemplate='ToastGeneric'> <texthint-callScenarioCenterAlign='true'>Andrew Bares</text> <texthint-callScenarioCenterAlign='true'>Incoming Call - Mobile</text> <imagesrc='ms-appx:///Images/InlineImage.png'hint-crop='circle'/> </binding> </visual> <actions> <actioncontent=''arguments='videoId=123'imageUri='ms-appx:///Images/Video.png'hint-buttonStyle='Success'hint-toolTip='Answer Video Call'/> <actioncontent=''arguments='callId=123'imageUri='ms-appx:///Images/Call.png'hint-buttonStyle='Success'hint-toolTip='Answer Phone Call'/> <actioncontent=''arguments='hangUpId=123'imageUri='ms-appx:///Images/HangUp.png'hint-buttonStyle='Critical'hint-toolTip='Hang Up'/> </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 notification or selects the context menu icon.
Note
On older devices, these additional context menu actions will simply appear as normal buttons on your notification.
The additional context menu actions you add (such as "Mute group chat for 1 hour") appear above the two default system entries.
varbuilder=newAppNotificationBuilder().AddText("Camping this weekend?").SetAppLogoOverride(newUri("ms-appx:///images/Reply.png"),AppNotificationImageCrop.Circle).AddButton(newAppNotificationButton("Mute group chat for 1 hour").AddArgument("action","mute").SetContextMenuPlacement());
The Windows Community Toolkit builder syntax doesn't currently support context menu actions, so we recommend using initializer syntax.
ToastContentcontent=newToastContent(){ ...Actions=newToastActionsCustom(){ContextMenuItems={newToastContextMenuItem("Mute group chat for 1 hour","action=muteId")}}};
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Camping this weekend?</text> <imageplacement='appLogoOverride'src='ms-appx:///images/Reply.png'hint-crop='circle'/> </binding> </visual> <actions> <actioncontent='Mute group chat for 1 hour'arguments='action=mute'placement='contextMenu'/> </actions> </toast>
Note
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 are specified within the Actions region of the app notification, meaning they are only visible when the notification is expanded.
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 the input field. The optional icon for the button, if provided, should be a 32x32 pixel image with no padding, white pixels set to transparent, and 100% scale.
varbuilder=newAppNotificationBuilder().AddTextBox("textBox","Type a reply","Reply").AddButton(AppNotificationButton("Send").AddArguments("action","Send").SetInputId("textBox")).BuildNotification();
varbuilder=newToastContentBuilder().AddInputTextBox("tbReply","Type a reply").AddButton(newToastButton().SetContent("Reply").SetTextBoxId("tbReply")// To place button next to text box, reference text box's id.SetImageUri(newUri("Assets/Reply.png",UriKind.Relative)).AddArgument("action","reply"));
<toastlaunch="app-defined-string"> <visual> <bindingtemplate="ToastGeneric"> <imageplacement="appLogoOverride"hint-crop="circle"src="https://picsum.photos/48?image=883"/> <text>Andrew Bares</text> <text>Shall we meet up at 8?</text> </binding> </visual> <actions> <inputid="textBox"type="text"placeHolderContent="Type a reply"/> <actioncontent="Send"arguments="action=reply&convId=9318"hint-inputId="textBox"imageUri="Assets/Reply.png"/> </actions> </toast>
You also can have one (or many) inputs with normal buttons displayed below the inputs.
// The Microsoft.Windows.AppNotifications.Builder syntax does not currently support quick reply text boxes.
newToastContentBuilder() ....AddInputTextBox("tbReply","Type a reply").AddButton(newToastButton().SetContent("Reply").AddArgument("action","reply")).AddButton(newToastButton().SetContent("Video call").AddArgument("action","videoCall"));
<toastlaunch="app-defined-string"> <visual> <bindingtemplate="ToastGeneric"> <imageplacement="appLogoOverride"hint-crop="circle"src="https://picsum.photos/48?image=883"/> <text>Andrew Bares</text> <text>Shall we meet up at 8?</text> </binding> </visual> <actions> <inputid="textBox"type="text"placeHolderContent="Type a reply"/> <actioncontent="Reply"arguments="action=reply&threadId=9218"/> <actioncontent="Video call"arguments="action=videocall&threadId=9218"activationType="foreground"/> </actions> </toast>
In addition to text boxes, you can also use a selection menu.
varbuilder=newAppNotificationBuilder().AddText("4th coffee?").AddText("When do you plan to come in tomorrow?").AddComboBox(newAppNotificationComboBox("time").SetTitle("Select an item:").AddItem("breakfast","Breakfast").AddItem("lunch","Lunch").AddItem("dinner","Dinner").SetSelectedItem("lunch")).AddButton(newAppNotificationButton("Reply").AddArgument("action","reply").AddArgument("threadId","9218").SetContextMenuPlacement()).AddButton(newAppNotificationButton("Call restaurant").AddArgument("action","videocall").AddArgument("threadId","9218").SetContextMenuPlacement());
varbuilder=newToastContentBuilder().AddText("4th coffee?").AddText("When do you plan to come in tomorrow?").AddToastInput(newToastSelectionBox("time"){DefaultSelectionBoxItemId="lunch",Items={newToastSelectionBoxItem("breakfast","Breakfast"),newToastSelectionBoxItem("lunch","Lunch"),newToastSelectionBoxItem("dinner","Dinner")}}).AddButton(newToastButton().SetContent("Reply").AddArgument("action","reply").AddArgument("threadId","9218")).AddButton(newToastButton().SetContent("Call restaurant").AddArgument("action","videoCall").AddArgument("threadId","9218"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>4th coffee?</text> <text>When do you plan to come in tomorrow?</text> </binding> </visual> <actions> <inputid='time'type='selection'title='Select an item:'defaultInput='lunch'> <selectionid='breakfast'content='Breakfast'/><selectionid='dinner'content='Dinner'/> <selectionid='lunch'content='Lunch'/> </input> <actioncontent='Reply'arguments='action=reply;threadId=9218'placement='contextMenu'/> <actioncontent='Call Restaurant'arguments='action=videocall;threadId=9218'placement='contextMenu'/> </actions> </toast>
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.
We link the Snooze button to the selection menu input using the SelectionBoxId property on the toast button.
The Microsoft.Windows.AppNotifications.Builder syntax does not currently support system activation. But this scenario is supported for Windows App SDK apps, and you can build notifications for this scenario using the Microsoft.Toolkit.Uwp.Notifications
APIs or raw XML.
// The Microsoft.Windows.AppNotifications.Builder syntax does not currently support system activation. // But this scenario is supported for Windows App SDK apps, and you can build notifications for this // scenario using the `Microsoft.Toolkit.Uwp.Notifications` APIs or raw XML.
newToastContentBuilder().SetToastScenario(ToastScenario.Reminder) ....AddToastInput(newToastSelectionBox("snoozeTime"){DefaultSelectionBoxItemId="15",Items={newToastSelectionBoxItem("5","5 minutes"),newToastSelectionBoxItem("15","15 minutes"),newToastSelectionBoxItem("60","1 hour"),newToastSelectionBoxItem("240","4 hours"),newToastSelectionBoxItem("1440","1 day")}}).AddButton(newToastButtonSnooze(){SelectionBoxId="snoozeTime"}).AddButton(newToastButtonDismiss());
<toast> <visual> <bindingtemplate="ToastGeneric"> <texthint-maxLines="1">Adaptive Tiles Meeting</text> <text>Conf Room 2001 / Building 135</text> <text>10:00 AM - 10:30 AM</text> </binding> </visual> <actions> <inputid="snoozeTime"type="selection"defaultInput="15"> <selectionid="1"content="1 minute"/> <selectionid="15"content="15 minutes"/> <selectionid="60"content="1 hour"/> <selectionid="240"content="4 hours"/> <selectionid="1440"content="1 day"/> </input> <actionactivationType="system"arguments="snooze"hint-inputId="snoozeTime"content="" /> <actionactivationType="system"arguments="dismiss"content=""/> </actions> </toast>
To use the system snooze and dismiss actions:
- Specify 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".
- Optionally specify the SelectionBoxId:
- 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: - Specify SelectionBoxId in the snooze action - Match the id of the input with the SelectionBoxId of the snooze action - Specify ToastSelectionBoxItem's value to be a nonNegativeInteger which represents snooze interval in minutes.
Custom audio has always been supported on Mobile, and is supported in Desktop Version 1511 (build 10586) or later. Custom audio can be referenced via the following paths:
- ms-appx:///
- ms-appdata:///
varbuilder=newAppNotificationBuilder().AddText("Notification text.").SetAudioUri(newUri("ms-appx:///Audio/NotificationSound.mp3"));
varbuilder=newToastContentBuilder().AddText("Notification text").AddAudio(newUri("ms-appx:///Audio/NotificationSound.mp3"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Notification text.</text> </binding> </visual> <audiosrc='ms-appx:///Audio/NotificationSound.mp3'/> </toast>
Alternatively, you can pick from the list of ms-winsoundevents, which have always been supported on both platforms.
varbuilder=newAppNotificationBuilder().AddText("Notification text.").SetAudioEvent(AppNotificationSoundEvent.Alarm,AppNotificationAudioLooping.Loop);
varbuilder=newToastContentBuilder().AddText("Notification text").AddAudio(newUri("ms-winsoundevent:Notification.Looping.Alarm"));
<toast> <visual> <bindingtemplate='ToastGeneric'> <text>Notification text.</text> </binding> </visual> <audiosrc='ms-winsoundevent:Notification.Looping.Alarm'loop='true'/> </toast>
See the audio schema page for information on audio in app notifications. To learn how to send an app notification that uses custom audio, see custom audio on toasts.
To create important notifications, alarms, reminders, and incoming call notifications, you simply use a normal app notification with a Scenario value assigned to it. The scenario adjusts a few behaviors to create a consistent and unified user experience. There are four possible Scenario values:
- Reminder
- Alarm
- IncomingCall
- Urgent
In the reminder scenario, the notification will stay on screen until the user dismisses it or takes action. On Windows Mobile, the app notification will also show pre-expanded. A reminder sound will be played. You must provide at least one button on your app notification. Otherwise, the notification will be treated as a normal notification.
varbuilder=newAppNotificationBuilder().AddText("Notification text.").SetScenario(AppNotificationScenario.Reminder);
varbuilder=newToastContentBuilder().AddText("Notification text.").SetToastScenario(ToastScenario.Reminder)
<toastscenario='reminder'> <visual> <bindingtemplate='ToastGeneric'> <text>Notification text.</text> </binding> </visual> </toast>
Alarms behave the same as reminders, except alarms will additionally loop audio with a default alarm sound. You must provide at least one button on your app notification. Otherwise, the notification will be treated as a normal notification.
varbuilder=newAppNotificationBuilder().AddText("Notification text.").SetScenario(AppNotificationScenario.Alarm).AddButton(newAppNotificationButton("Dismiss").AddArgument("action","dismiss"));
varbuilder=newToastContentBuilder().AddText("Notification text").SetToastScenario(ToastScenario.Alarm).AddButton(newToastButton().SetContent("Dismiss").AddArgument("action","dismiss"));
<toastscenario='alarm'> <visual> <bindingtemplate='ToastGeneric'> <text>Notification text.</text> </binding> </visual> <actions> <actioncontent='Dismiss'arguments='action=dismiss'/> </actions> </toast>
Incoming call notifications are displayed pre-expanded in a special call format and stay on the user's screen till dismissed. Ringtone audio will loop by default. On Windows Mobile devices, they display full screen.
varbuilder=newAppNotificationBuilder().SetScenario(AppNotificationScenario.IncomingCall).AddText("Andrew Bares",newAppNotificationTextProperties().SetIncomingCallAlignment()).AddText("incoming call - mobile",newAppNotificationTextProperties().SetIncomingCallAlignment()).SetInlineImage(newUri("ms-appx:///images/profile.png"),AppNotificationImageCrop.Circle).AddButton(newAppNotificationButton("Text reply").SetToolTip("Text reply").SetIcon(newUri("ms-appx:///images/reply.png")).AddArgument("textId","123")).AddButton(newAppNotificationButton("Reminder").SetToolTip("Reminder").SetIcon(newUri("ms-appx:///images/reminder.png")).AddArgument("reminderId","123")).AddButton(newAppNotificationButton("Ignore").SetToolTip("Ignore").SetIcon(newUri("ms-appx:///images/ignore.png")).AddArgument("ignoreId","123")).AddButton(newAppNotificationButton("Answer").SetToolTip("Answer").SetIcon(newUri("ms-appx:///images/answer.png")).AddArgument("answerId","123"));
varbuilder=newToastContentBuilder().SetToastScenario(ToastScenario.IncomingCall).AddText("Andrew Bares").AddText("incoming call - mobile").AddInlineImage(newUri("ms-appx:///images/profile.png"),"Andrew Bares",null,AdaptiveImageCrop.Circle).AddButton(newToastButton().SetContent("Text reply").SetImageUri(newUri("ms-appx:///images/reply.png")).AddArgument("textId","123")).AddButton(newToastButton().SetContent("Reminder").SetImageUri(newUri("ms-appx:///images/reminder.png")).AddArgument("reminderId","123")).AddButton(newToastButton().SetContent("Ignore").SetImageUri(newUri("ms-appx:///images/ignore.png")).AddArgument("ignoreId","123")).AddButton(newToastButton().SetContent("Answer").SetImageUri(newUri("ms-appx:///images/answer.png")).AddArgument("answerId","123"));
<toastscenario='incomingCall'> <visual> <bindingtemplate='ToastGeneric'> <texthint-callScenarioCenterAlign='true'>Andrew Bares</text> <texthint-callScenarioCenterAlign='true'>incoming call - mobile</text> <imagesrc='ms-appx:///images/profile.png'hint-crop='circle'/> </binding> </visual> <actions> <actioncontent='Text reply'arguments='textId=123'imageUri='ms-appx:///images/reply.png'hint-toolTip='Text reply'/> <actioncontent='Reminder'arguments='reminderId=123'imageUri='ms-appx:///images/reminder.png'hint-toolTip='Reminder'/> <actioncontent='Ignore'arguments='ignoreId=123'imageUri='ms-appx:///images/ignore.png'hint-toolTip='Ignore'/> <actioncontent='Answer'arguments='answerId=123'imageUri='ms-appx:///images/answer.png'hint-toolTip='Answer'/> </actions> </toast>
Important
Requires: You must be running Windows Insider Preview Build 22546 or later to use important notifications.
Important notifications allow users to have more control over what 1st party and 3rd party apps can send them high-priority app notifications (urgent/important) that can break through Focus Assist (Do not Disturb). This can be modified in the notifications settings.
varbuilder=newAppNotificationBuilder().AddText("Adaptive Tiles Meeting",newAppNotificationTextProperties().SetMaxLines(1)).AddText("Conf Room 2001 / Building 135").AddText("10:00 AM - 10:30 AM");if(AppNotificationBuilder.IsUrgentScenarioSupported()){builder.SetScenario(AppNotificationScenario.Urgent);}
// The builder syntax does not support important notifications yet.
<toastscenario='urgent'> <visual> <bindingtemplate='ToastGeneric'> <texthint-maxLines='1'>Adaptive Tiles Meeting</text> <text>Conf Room 2001 / Building 135</text> <text>10:00 AM - 10:30 AM</text> </binding> </visual> </toast>
Your tiles and app notifications 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.
To learn how to handle app activations (the user clicking your toast or buttons on the toast), see Send local toast.