-->
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple may provide or recommend responses as a possible solution based on the information provided; every potential issue may involve several factors not detailed in the conversations captured in an electronic forum and Apple can therefore provide no guarantee as to the. Our code sample will use this package. At the end of the article we'll provide the 'plain' code snippets that don't use any NuGet packages. This package allows you to create toast notifications without using XML. Step 2: Add namespace declarations. Windows.UI.Notifications includes the toast APIs.
A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app.
This quickstart walks you through the steps to create, deliver, and display a Windows 10 toast notification using rich content and interactive actions. This quickstart uses local notifications, which are the simplest notification to implement. All types of apps (WPF, UWP, WinForms, console) can send notifications!
Important
If you're writing a C++ app, please see the C++ UWP or C++ WRL documentation.
Step 1: Install NuGet package
Within your Visual Studio solution, right click your project, click 'Manage NuGet Packages.' and search for and install the Microsoft.Toolkit.Uwp.Notifications
NuGet package version 7.0 or greater.
Important
.NET Framework desktop apps that still use packages.config must migrate to PackageReference, otherwise the Windows 10 SDKs won't be referenced correctly. In your project, right-click on 'References', and click 'Migrate packages.config to PackageReference'.
.NET Core 3.0 WPF apps must update to .NET Core 3.1, otherwise the APIs will be absent.
Our code sample will use this package. This package allows you to create toast notifications without using XML, and also allows desktop apps to send toasts.
Step 2: Send a toast
In Windows 10, your toast notification content is described using an adaptive language that allows great flexibility with how your notification looks. For more information, see the toast content documentation.
We'll start with a simple text-based notification. Construct the notification content (using the Notifications library), and show the notification! Note that the namespace is Microsoft.Toolkit.Uwp.Notifications
.
Etcher bootable usb. Try running this code and you should see the notification appear!
Step 3: Handling activation
After showing a notification, you likely need to handle the user clicking the notification (whether that means bringing up specific content after the user clicks it, opening your app in general, or performing an action when the user clicks the notification).
The steps for handling activation differ for UWP, Desktop (MSIX), and Desktop (unpackaged) apps.
When the user clicks your notification (or a button on the notification with foreground activation), your app's App.xaml.csOnActivated will be invoked, and the arguments you added will be returned.
App.xaml.cs
Important
You must initialize your frame and activate your window just like your OnLaunched code. OnLaunched is NOT called if the user clicks on your toast, even if your app was closed and is launching for the first time. We often recommend combining OnLaunched and OnActivated into your own OnLaunchedOrActivated
method since the same initialization needs to occur in both.
First, in your Package.appxmanifest, add:
- Declaration for xmlns:com
- Declaration for xmlns:desktop
- In the IgnorableNamespaces attribute, com and desktop
- desktop:Extension for windows.toastNotificationActivation to declare your toast activator CLSID (using a new GUID of your choice).
- MSIX only: com:Extension for the COM activator using the GUID from step #4. Be sure to include the
Arguments='-ToastActivated'
so that you know your launch was from a notification
Package.appxmanifest
Then, in your app's startup code (App.xaml.cs OnStartup for WPF), subscribe to the OnActivated event.
When the user clicks any of your notifications (or a button on the notification), the following will happen.
If your app is currently running.
- The ToastNotificationManagerCompat.OnActivated event will be invoked on a background thread.
If your app is currently closed.
- Your app's EXE will be launched and
ToastNotificationManagerCompat.WasCurrentProcessToastActivated()
will return true to indicate the process was started due to a modern activation and that the event handler will soon be invoked. - Then, theToastNotificationManagerCompat.OnActivated event will be invoked on a background thread.
When the user clicks any of your notifications (or a button on the notification), the following will happen.
If your app is currently running.
- The ToastNotificationManagerCompat.OnActivated event will be invoked on a background thread.
If your app is currently closed.
- Your app's EXE will be launched and
ToastNotificationManagerCompat.WasCurrentProcessToastActivated()
will return true to indicate the process was started due to a modern activation and that the event handler will soon be invoked. - Then, theToastNotificationManagerCompat.OnActivated event will be invoked on a background thread.
In your app's startup code (App.xaml.cs OnStartup for WPF), subscribe to the OnActivated event.
Step 4: Handling uninstallation
You don't need to do anything! When UWP apps are uninstalled, all notifications and any other related resources are automatically cleaned up.
You don't need to do anything! When MSIX apps are uninstalled, all notifications and any other related resources are automatically cleaned up.
If your app has an uninstaller, in your uninstaller you should call ToastNotificationManagerCompat.Uninstall();
. If your app is a 'portable app' without an installer, consider calling this method upon app exit unless you have notifications that are meant to persist after your app is closed.
The uninstall method will clean up any scheduled and current notifications, remove any associated registry values, and remove any associated temporary files that were created by the library.
Adding images
You can add rich content to notifications. We'll add an inline image and a profile (app logo override) image.
Note Family feud generator.
Images can be used from the app's package, the app's local storage, or from the web. As of the Fall Creators Update, web images can be up to 3 MB on normal connections and 1 MB on metered connections. On devices not yet running the Fall Creators Update, web images must be no larger than 200 KB.
Important
Http images are only supported in UWP/MSIX/sparse apps that have the internet capability in their manifest. desktop non-MSIX/sparse apps do not support http images; you must download the image to your local app data and reference it locally.
Adding buttons and inputs
You can add buttons and inputs to make your notifications interactive. Buttons can launch your foreground app, a protocol, or your background task. We'll add a reply text box, a 'Like' button, and a 'View' button that opens the image.
The activation of foreground buttons are handled in the same way as the main toast body (your App.xaml.cs OnActivated will be called).
Note that arguments added to the top-level toast (like conversation ID) will also be returned when the buttons are clicked, as long as buttons use the AddArgument API as seen above (if you custom assign arguments on a button, the top-level arguments won't be included).
Handling background activation
When you specify background activation on your toast (or on a button inside the toast), your background task will be executed instead of activating your foreground app.
For more information on background tasks, please see Support your app with background tasks.
If you are targeting build 14393 or higher, you can use in-process background tasks, which greatly simplify things. Note that in-process background tasks will fail to run on older versions of Windows. We'll use an in-process background task in this code sample.
Then in your App.xaml.cs, override the OnBackgroundActivated method. You can then retrieve the pre-defined arguments and user input, similar to the foreground activation.
App.xaml.cs
For desktop applications, background activations are handled the same as foreground activations (your OnActivated event handler will be triggered). You can choose to not show any UI and close your app after handling activation.
Set an expiration time
In Windows 10, all toast notifications go in Action Center after they are dismissed or ignored by the user, so users can look at your notification after the popup is gone.
However, if the message in your notification is only relevant for a period of time, you should set an expiration time on the toast notification so the users do not see stale information from your app. For example, if a promotion is only valid for 12 hours, set the expiration time to 12 hours. In the code below, we set the expiration time to be 2 days.
Note
The default and maximum expiration time for local toast notifications is 3 days.
Provide a primary key for your toast
If you want to programmatically remove or replace the notification you send, you need to use the Tag property (and optionally the Group property) to provide a primary key for your notification. Then, you can use this primary key in the future to remove or replace the notification.
To see more details on replacing/removing already delivered toast notifications, please see Quickstart: Managing toast notifications in action center (XAML).
Toast Result Code 430
Tag and Group combined act as a composite primary key. Group is the more generic identifier, where you can assign groups like 'wallPosts', 'messages', 'friendRequests', etc. And then Tag should uniquely identify the notification itself from within the group. By using a generic group, you can then remove all notifications from that group by using the RemoveGroup API.
Clear your notifications
Apps are responsible for removing and clearing their own notifications. When your app is launched, we do NOT automatically clear your notifications.
Windows will only automatically remove a notification if the user explicitly clicks the notification.
Here's an example of what a messaging app should do…
- User receives multiple toasts about new messages in a conversation
- User taps one of those toasts to open the conversation
- The app opens the conversation and then clears all toasts for that conversation (by using RemoveGroup on the app-supplied group for that conversation)
- User's Action Center now properly reflects the notification state, since there are no stale notifications for that conversation left in Action Center.
To learn about clearing all notifications or removing specific notifications, see Quickstart: Managing toast notifications in action center (XAML).
Resources
Toast Result Code 433
-->The following describes all of the properties and elements within toast content.
If you would rather use raw XML instead of the Notifications library, please see the XML schema.
- ToastVisual
- ToastBindingGeneric
ToastContent
ToastContent is the top level object that describes a notification's content, including visuals, actions, and audio.
Property | Type | Required | Description |
---|---|---|---|
Launch | string | false | A string that is passed to the application when it is activated by the Toast. The format and contents of this string are defined by the app for its own use. When the user taps or clicks the Toast to launch its associated app, the launch string provides the context to the app that allows it to show the user a view relevant to the Toast content, rather than launching in its default way. |
Visual | ToastVisual | true | Describes the visual portion of the toast notification. |
Actions | IToastActions | false | Optionally create custom actions with buttons and inputs. |
Audio | ToastAudio | false | Describes the audio portion of the toast notification. |
ActivationType | ToastActivationType | false | Specifies what activation type will be used when the user clicks the body of this Toast. |
ActivationOptions | ToastActivationOptions | false | New in Creators Update: Additional options relating to activation of the toast notification. |
Scenario | ToastScenario | false | Declares the scenario your toast is used for, like an alarm or reminder. |
DisplayTimestamp | DateTimeOffset? | false | New in Creators Update: Override the default timestamp with a custom timestamp representing when your notification content was actually delivered, rather than the time the notification was received by the Windows platform. |
Header | ToastHeader | false | New in Creators Update: Add a custom header to your notification to group multiple notifications together within Action Center. |
ToastScenario
Specifies what scenario the toast represents.
Value | Meaning |
---|---|
Default | The normal toast behavior. |
Reminder | A reminder notification. This will be displayed pre-expanded and stay on the user's screen till dismissed. |
Alarm | An alarm notification. This will be displayed pre-expanded and stay on the user's screen till dismissed. Audio will loop by default and will use alarm audio. |
IncomingCall | An incoming call notification. This will be displayed pre-expanded in a special call format and stay on the user's screen till dismissed. Audio will loop by default and will use ringtone audio. |
ToastVisual
The visual portion of toasts contains the bindings, which contains text, images, adaptive content, and more.
Property | Type | Required | Description |
---|---|---|---|
BindingGeneric | ToastBindingGeneric | true | The generic toast binding, which can be rendered on all devices. This binding is required and cannot be null. |
BaseUri | Uri | false | A default base URL that is combined with relative URLs in image source attributes. |
AddImageQuery | bool? | false | Set to 'true' to allow Windows to append a query string to the image URL supplied in the toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language; for instance, a value of 'www.website.com/images/hello.png' given in the notification becomes 'www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us' |
Language | string | false | The target locale of the visual payload when using localized resources, specified as BCP-47 language tags such as 'en-US' or 'fr-FR'. This locale is overridden by any locale specified in binding or text. If not provided, the system locale will be used instead. |
ToastBindingGeneric
The generic binding is the default binding for toasts, and is where you specify the text, images, adaptive content, and more.
Property | Type | Required | Description |
---|---|---|---|
Children | IList | false | The contents of the body of the Toast, which can include text, images, and groups (added in Anniversary Update). Text elements must come before any other elements, and only 3 text elements are supported. If a text element is placed after any other element, it will either be pulled to the top or dropped. And finally, certain text properties like HintStyle aren't supported on the root children text elements, and only work inside an AdaptiveSubgroup. If you use AdaptiveGroup on devices without the Anniversary Update, the group content will simply be dropped. |
AppLogoOverride | ToastGenericAppLogo | false | An optional logo to override the app logo. |
HeroImage | ToastGenericHeroImage | false | An optional featured 'hero' image that is displayed on the toast and within Action Center. |
Attribution | ToastGenericAttributionText | false | Optional attribution text which will be displayed at the bottom of the toast notification. |
BaseUri | Uri | false | A default base URL that is combined with relative URLs in image source attributes. |
AddImageQuery | bool? | false | Set to 'true' to allow Windows to append a query string to the image URL supplied in the toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language; for instance, a value of 'www.website.com/images/hello.png' given in the notification becomes 'www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us' |
Language | string | false | The target locale of the visual payload when using localized resources, specified as BCP-47 language tags such as 'en-US' or 'fr-FR'. This locale is overridden by any locale specified in binding or text. If not provided, the system locale will be used instead. |
IToastBindingGenericChild
Marker interface for toast child elements that include text, images, groups, and more.
Implementations |
---|
AdaptiveText |
AdaptiveImage |
AdaptiveGroup |
AdaptiveProgressBar |
AdaptiveText
An adaptive text element. If placed in the top level ToastBindingGeneric.Children, only HintMaxLines will be applied. But if this is placed as a child of a group/subgroup, full text styling is supported.
Property | Type | Required | Description |
---|---|---|---|
Text | string or BindableString | false | The text to display. Data binding support added in Creators Update, but only works for top-level text elements. |
HintStyle | AdaptiveTextStyle | false | The style controls the text's font size, weight, and opacity. Only works for text elements inside a group/subgroup. |
HintWrap | bool? | false | Set this to true to enable text wrapping. Top-level text elements ignore this property and always wrap (you can use HintMaxLines = 1 to disable wrapping for top-level text elements). Text elements inside groups/subgroups default to false for wrapping. |
HintMaxLines | int? | false | The maximum number of lines the text element is allowed to display. |
HintMinLines | int? | false | The minimum number of lines the text element must display. Only works for text elements inside a group/subgroup. |
HintAlign | AdaptiveTextAlign | false | The horizontal alignment of the text. Only works for text elements inside a group/subgroup. |
Language | string | false | The target locale of the XML payload, specified as a BCP-47 language tags such as 'en-US' or 'fr-FR'. The locale specified here overrides any other specified locale, such as that in binding or visual. If this value is a literal string, this attribute defaults to the user's UI language. If this value is a string reference, this attribute defaults to the locale chosen by Windows Runtime in resolving the string. |
BindableString
A binding value for strings.
Property | Type | Required | Description |
---|---|---|---|
BindingName | string | true | Gets or sets the name that maps to your binding data value. |
AdaptiveTextStyle
Text style controls font size, weight, and opacity. Subtle opacity is 60% opaque.
Value | Meaning |
---|---|
Default | Default value. Style is determined by the renderer. |
Caption | Smaller than paragraph font size. |
CaptionSubtle | Same as Caption but with subtle opacity. |
Body | Paragraph font size. |
BodySubtle | Same as Body but with subtle opacity. |
Base | Paragraph font size, bold weight. Essentially the bold version of Body. |
BaseSubtle | Same as Base but with subtle opacity. |
Subtitle | H4 font size. |
SubtitleSubtle | Same as Subtitle but with subtle opacity. |
Title | H3 font size. |
TitleSubtle | Same as Title but with subtle opacity. |
TitleNumeral | Same as Title but with top/bottom padding removed. |
Subheader | H2 font size. |
SubheaderSubtle | Same as Subheader but with subtle opacity. |
SubheaderNumeral | Same as Subheader but with top/bottom padding removed. |
Header | H1 font size. |
HeaderSubtle | Same as Header but with subtle opacity. |
HeaderNumeral | Same as Header but with top/bottom padding removed. |
AdaptiveTextAlign
Bo advanced warfare. Controls the horizontal alignmen of text.
Value | Meaning |
---|---|
Default | Default value. Alignment is automatically determined by the renderer. |
Auto | Alignment determined by the current language and culture. |
Left | Horizontally align the text to the left. |
Center | Horizontally align the text in the center. |
Right | Horizontally align the text to the right. |
AdaptiveImage
An inline image.
Property | Type | Required | Description |
---|---|---|---|
Source | string | true | The URL to the image. ms-appx, ms-appdata, and http are supported. As of the Fall Creators Update, web images can be up to 3 MB on normal connections and 1 MB on metered connections. On devices not yet running the Fall Creators Update, web images must be no larger than 200 KB. |
HintCrop | AdaptiveImageCrop | false | New in Anniversary Update: Control the desired cropping of the image. |
HintRemoveMargin | bool? | false | By default, images inside groups/subgroups have an 8px margin around them. You can remove this margin by setting this property to true. |
HintAlign | AdaptiveImageAlign | false | The horizontal alignment of the image. Only works for images inside a group/subgroup. |
AlternateText | string | false | Alternate text describing the image, used for accessibility purposes. |
AddImageQuery | bool? | false | Set to 'true' to allow Windows to append a query string to the image URL supplied in the toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language; for instance, a value of 'www.website.com/images/hello.png' given in the notification becomes 'www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us' |
AdaptiveImageCrop
Specifies the desired cropping of the image.
Value | Meaning |
---|---|
Default | Default value. Cropping behavior determined by renderer. |
None | Image is not cropped. |
Circle | Image is cropped to a circle shape. |
AdaptiveImageAlign
Specifies the horizontal alignment for an image.
Value | Meaning |
---|---|
Default | Default value. Alignment behavior determined by renderer. |
Stretch | Image stretches to fill available width (and potentially available height too, depending on where the image is placed). |
Left | Align the image to the left, displaying the image at its native resolution. |
Center | Align the image in the center horizontally, displayign the image at its native resolution. |
Right | Align the image to the right, displaying the image at its native resolution. |
AdaptiveGroup
New in Anniversary Update: Groups semantically identify that the content in the group must either be displayed as a whole, or not displayed if it cannot fit. Groups also allow creating multiple columns.
Property | Type | Required | Description |
---|---|---|---|
Children | IList | false | Subgroups are displayed as vertical columns. You must use subgroups to provide any content inside an AdaptiveGroup. |
AdaptiveSubgroup
New in Anniversary Update: Subgroups are vertical columns that can contain text and images.
Property | Type | Required | Description |
---|---|---|---|
Children | IList | false | AdaptiveText and AdaptiveImage are valid children of subgroups. |
HintWeight | int? | false | Control the width of this subgroup column by specifying the weight, relative to the other subgroups. |
HintTextStacking | AdaptiveSubgroupTextStacking | false | Control the vertical alignment of this subgroup's content. |
IAdaptiveSubgroupChild
Marker interface for subgroup children.
Implementations |
---|
AdaptiveText |
AdaptiveImage |
AdaptiveSubgroupTextStacking
TextStacking specifies the vertical alignment of content.
Value | Meaning |
---|---|
Default | Default value. Renderer automatically selects the default vertical alignment. |
Top | Vertical align to the top. |
Center | Vertical align to the center. |
Bottom | Vertical align to the bottom. |
AdaptiveProgressBar
New in Creators Update: A progress bar. Only supported on toasts on Desktop, build 15063 or newer.
Property | Type | Required | Description |
---|---|---|---|
Title | string or BindableString | false | Gets or sets an optional title string. Supports data binding. |
Value | double or AdaptiveProgressBarValue or BindableProgressBarValue | false | Gets or sets the value of the progress bar. Supports data binding. Defaults to 0. |
ValueStringOverride | string or BindableString | false | Gets or sets an optional string to be displayed instead of the default percentage string. If this isn't provided, something like '70%' will be displayed. |
Status | string or BindableString | true | Gets or sets a status string (required), which is displayed underneath the progress bar on the left. This string should reflect the status of the operation, like 'Downloading.' or 'Installing.' |
AdaptiveProgressBarValue
A class that represents the progress bar's value.
Property | Type | Required | Description |
---|---|---|---|
Value | double | false | Gets or sets the value (0.0 - 1.0) representing the percent complete. |
IsIndeterminate | bool | false | Gets or sets a value indicating whether the progress bar is indeterminate. If this is true, Value will be ignored. |
BindableProgressBarValue
A bindable progress bar value.
Toast Result Code 43 Years
Property | Type | Required | Description |
---|---|---|---|
BindingName | string | true | Gets or sets the name that maps to your binding data value. |
ToastGenericAppLogo
A logo to be displayed instead of the app logo.
Property | Type | Required | Description |
---|---|---|---|
Source | string | true | The URL to the image. ms-appx, ms-appdata, and http are supported. Http images must be 200 KB or less in size. |
HintCrop | ToastGenericAppLogoCrop | false | Specify how you would like the image to be cropped. |
AlternateText | string | false | Alternate text describing the image, used for accessibility purposes. |
AddImageQuery | bool? | false | Set to 'true' to allow Windows to append a query string to the image URL supplied in the toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language; for instance, a value of 'www.website.com/images/hello.png' given in the notification becomes 'www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us' |
ToastGenericAppLogoCrop
Controls the cropping of the app logo image.
Value | Meaning |
---|---|
Default | Cropping uses the default behavior of the renderer. |
None | Image is not cropped, displayed square. |
Circle | Image is cropped to a circle. |
ToastGenericHeroImage
A featured 'hero' image that is displayed on the toast and within Action Center.
Property | Type | Required | Description |
---|---|---|---|
Source | string | true | The URL to the image. ms-appx, ms-appdata, and http are supported. Http images must be 200 KB or less in size. |
AlternateText | string | false | Alternate text describing the image, used for accessibility purposes. |
AddImageQuery | bool? | false | Set to 'true' to allow Windows to append a query string to the image URL supplied in the toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language; for instance, a value of 'www.website.com/images/hello.png' given in the notification becomes 'www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us' |
ToastGenericAttributionText
Attribution text displayed at the bottom of the toast notification.
Property | Type | Required | Description |
---|---|---|---|
Text | string | true | The text to display. |
Language | string | false | The target locale of the visual payload when using localized resources, specified as BCP-47 language tags such as 'en-US' or 'fr-FR'. If not provided, the system locale will be used instead. |
IToastActions
Marker interface for toast actions/inputs.
Implementations |
---|
ToastActionsCustom |
ToastActionsSnoozeAndDismiss |
ToastActionsCustom
Implements IToastActions
Create your own custom actions and inputs, using controls like buttons, text boxes, and selection inputs.
Property | Type | Required | Description |
---|---|---|---|
Inputs | IList | false | Inputs like text boxes and selection inputs. Only up to 5 inputs are allowed. |
Buttons | IList | false | Buttons are displayed after all the inputs (or adjacent to an input if the button is used as a quick reply button). Only up to 5 buttons are allowed (or fewer if you also have context menu items). |
ContextMenuItems | IList | false | New in Anniversary Update: Custom context menu items, providing additional actions if the user right clicks the notification. You can only have up to 5 buttons and context menu items combined. |
IToastInput
Marker interface for toast inputs.
Implementations |
---|
ToastTextBox |
ToastSelectionBox |
ToastTextBox
Implements IToastInput
A text box control that the user can type text into.
Property | Type | Required | Description |
---|---|---|---|
Id | string | true | The Id is required, and is used to map the user-inputted text into a key-value pair of id/value which your app later consumes. |
Title | string | false | Title text to display above the text box. |
PlaceholderContent | string | false | Placeholder text to be displayed on the text box when the user hasn't typed any text yet. |
DefaultInput | string | false | The initial text to place in the text box. Leave this null for a blank text box. |
ToastSelectionBox
Implements IToastInput
A selection box control, which lets users pick from a dropdown list of options.
Property | Type | Required | Description |
---|---|---|---|
Id | string | true | The Id is required. If the user selected this item, this Id will be passed back to your app's code, representing which selection they chose. |
Content | string | true | Content is required, and is a string that is displayed on the selection item. |
ToastSelectionBoxItem
A selection box item (an item that the user can select from the drop down list).
Property | Type | Required | Description |
---|---|---|---|
Id | string | true | The Id is required, and is used to map the user-inputted text into a key-value pair of id/value which your app later consumes. |
Title | string | false | Title text to display above the selection box. |
DefaultSelectionBoxItemId | string | false | This controls which item is selected by default, and refers to the Id property of the ToastSelectionBoxItem. If you do not provide this, the default selection will be empty (user sees nothing). |
Items | IList | false | The selection items that the user can pick from in this SelectionBox. Only 5 items can be added. |
IToastButton
Marker interface for toast buttons.
Implementations |
---|
ToastButton |
ToastButtonSnooze |
ToastButtonDismiss |
ToastButton
Implements IToastButton
A button that the user can click.
Property | Type | Required | Description |
---|---|---|---|
Content | string | true | Required. The text to display on the button. |
Arguments | string | true | Required. App-defined string of arguments that the app will later receive if the user clicks this button. |
ActivationType | ToastActivationType | false | Controls what type of activation this button will use when clicked. Defaults to Foreground. |
ActivationOptions | ToastActivationOptions | false | New in Creators Update: Gets or sets additional options relating to activation of the toast button. |
ToastActivationType
Decides the type of activation that will be used when the user interacts with a specific action.
Value | Meaning |
---|---|
Foreground | Default value. Your foreground app is launched. |
Background | Your corresponding background task (assuming you set everything up) is triggered, and you can execute code in the background (like sending the user's quick reply message) without interrupting the user. |
Protocol | Launch a different app using protocol activation. |
ToastActivationOptions
New in Creators Update: Additional options relating to activation.
Property | Type | Required | Description |
---|---|---|---|
AfterActivationBehavior | ToastAfterActivationBehavior | false | New in Fall Creators Update: Gets or sets the behavior that the toast should use when the user invokes this action. This only works on Desktop, for ToastButton and ToastContextMenuItem. |
ProtocolActivationTargetApplicationPfn | string | false | If you are using ToastActivationType.Protocol, you can optionally specify the target PFN, so that regardless of whether multiple apps are registered to handle the same protocol uri, your desired app will always be launched. |
ToastAfterActivationBehavior
Specifies the behavior that the toast should use when the user takes action on the toast.
Value | Meaning |
---|---|
Default | Default behavior. The toast will be dismissed when the user takes action on the toast. |
PendingUpdate | After the user clicks a button on your toast, the notification will remain present, in a 'pending update' visual state. You should immediately update your toast from a background task so that the user does not see this 'pending update' visual state for too long. |
ToastButtonSnooze
Battle net linux. Implements IToastButton
A system-handled snooze button that automatically handles snoozing of the notification.
Property | Type | Required | Description |
---|---|---|---|
CustomContent | string | false | Optional custom text displayed on the button that overrides the default localized 'Snooze' text. |
ToastButtonDismiss
Implements IToastButton
A system-handled dismiss button that dismisses the notification when clicked.
Property | Type | Required | Description |
---|---|---|---|
CustomContent | string | false | Optional custom text displayed on the button that overrides the default localized 'Dismiss' text. |
ToastActionsSnoozeAndDismiss
*Implements IToastActions Pdf expert edit and sign pdf 2 2 17.
Automatically constructs a selection box for snooze intervals, and snooze/dismiss buttons, all automatically localized, and snoozing logic is automatically handled by the system.
Property | Type | Required | Description |
---|---|---|---|
ContextMenuItems | IList | false | New in Anniversary Update: Custom context menu items, providing additional actions if the user right clicks the notification. You can only have up to 5 items. |
ToastContextMenuItem
A context menu item entry.
Property | Type | Required | Description |
---|---|---|---|
Content | string | true | Required. The text to display. |
Arguments | string | true | Required. App-defined string of arguments that the app can later retrieve once it is activated when the user clicks the menu item. |
ActivationType | ToastActivationType | false | Controls what type of activation this menu item will use when clicked. Defaults to Foreground. |
ActivationOptions | ToastActivationOptions | false | New in Creators Update: Additional options relating to activation of the toast context menu item. |
ToastAudio
Specify audio to be played when the Toast notification is received.
Property | Type | Required | Description |
---|---|---|---|
Src | uri | false | The media file to play in place of the default sound. Only ms-appx and ms-appdata are supported. |
Loop | boolean | false | Set to true if the sound should repeat as long as the Toast is shown; false to play only once (default). |
Silent | boolean | false | True to mute the sound; false to allow the toast notification sound to play (default). |
ToastHeader
New in Creators Update: A custom header that groups multiple notifications together within Action Center.
Property | Type | Required | Description |
---|---|---|---|
Id | string | true | A developer-created identifier that uniquely identifies this header. If two notifications have the same header id, they will be displayed underneath the same header in Action Center. |
Title | string | true | A title for the header. |
Arguments | string | true | Gets or sets a developer-defined string of arguments that is returned to the app when the user clicks this header. Cannot be null. |
ActivationType | ToastActivationType | false | Gets or sets the type of activation this header will use when clicked. Defaults to Foreground. Note that only Foreground and Protocol are supported. |
ActivationOptions | ToastActivationOptions | false | Gets or sets additional options relating to activation of the toast header. |