[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Collapse]Messages, Notifications and Dialogs
    XtraMessageBox
    Input Box
    XtraDialog
    Flyout Dialog
    Flyout Panel
   [Expand]Alert Windows
    Toast Notification Manager
    WinRTLiveTileManager
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Toast Notification Manager

The Toast Notification Manager component shows toast notifications - a Windows 10 version of alert windows.

Note

  • Toast notifications can only be displayed in Windows 8.0 or higher. For older Windows versions, use alert windows instead.
  • Windows displays toast notifications only for those apps that are pinned to the Start menu.

An application can display multiple notifications simultaneously, or one notification multiple times at once. The ToastNotification object has nine content templates, and can play a sound.

Expanded Create Notifications

Follow the steps below to create toast notifications.

  1. Locate the ToastNotificationManager component in Visual Studio's toolbox and drop it onto the form.

  2. Windows displays toast notifications only for those apps that are pinned to the Start menu, so make sure your application has a valid shortcut with an Application User Model ID. For debugging purposes, invoke the component's smart tag and click the "Create Application Shortcut" link.

  3. Invoke the manager's smart-tag and click the Edit Notifications... link.

  4. In the Collection Editor dialog, click Add to add a notification. This creates new ToastNotification objects and adds them to the manager's ToastNotificationsManager.Notifications collection. You can customize the notification settings in the property grid.

  5. To display a specific notification, use the ToastNotificationsManager.ShowNotification method.

Expanded Manage End-User Interactions

Depending on end user actions, the following events occur.

  • ToastNotificationsManager.Activated - occurs if an end user clicks this notification. Handle this event to check which notification was clicked, and perform actions depending on the result. The code below illustrates an example.
  • ToastNotificationsManager.UserCancelled - occurs if an end user closes the notification.
  • ToastNotificationsManager.TimedOut - occurs when an end user does not respond to the notification and the notification is hidden after a certain period. The code below re-sends timed out notifications.
  • ToastNotificationsManager.Hidden - occurs when a toast notification is hidden via the ToastNotificationsManager.HideNotification or ToastNotificationsManager.HideNotifications method.
  • ToastNotificationsManager.Dropped - fires when a notification is canceled due to end user's system settings.

Expanded Customize Notifications with the "Generic" Template

The following XML markup is a sample toast notification's content layout:

You can handle the ToastNotificationsManager.UpdateToastContent event to modify this template using the System.XML namespace’s API. For instance, the following code adds a group with two subgroups to the notification layout. Each subgroup displays two additional text blocks, arranged vertically.

Expanded Buttons

Handle the following events to display a button in a notification:

The code below shows sample handlers.

Expanded User Input

The Generic toast template allows you to add input boxes and selection menus to notifications.

To handle end-user interactions with these elements, an Activator is required. The latter is a descendant of the DevExpress.XtraBars.ToastNotifications.ToastNotificationActivator class. Mark this descendant with the ComVisible and Guid attributes to allow the Component Object Model (COM) to create and access instances of this class. In the sample below, a message box shows which notification button a user has pressed, what text the user entered, and which time interval this user selected. Change the OnActivate method override to implement your own functionality.

Tip

You can use on-line GUID generators to randomly generate a valid GUID. Note that all GUIDs must be unique.

Important

  • If you have clicked the "Create Application Shortcut" link in the Toast Notification Manager's smart-tag to debug notifications, click the "Update Application Shortcut" link every time you change the Activator class. Otherwise, notifications will not reflect your changes.
  • Component Object Model invokes the OnActivate method in a worker thread. Make sure all calls to controls and components from this method are performed in a thread-safe way.

To assign this custom Activator to the Toast Notification Manager, specify the ToastNotificationsManager.ApplicationActivator property at design time...

...or call RegisterApplicationActivator/UnregisterApplicationActivator methods in code (hidden from IntelliSense).

Important

The Custom Activator requires that the application shortcut contains a unique application ID (ToastNotificationsManager.ApplicationId) and a CLSID that points to your COM class (a GUID passed to the Guid attribute). Additionally, the application must be registered as a local COM server that can be invoked when users interact with toasts. To do that, create the following registry key when deploying the application:

  • Key: HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{--your-GUID-here--}\LocalServer32
  • Value: C:\Users\Sample\Desktop\YourApplication.exe (specify an actual path to an executable)

Expanded Notes

  • The notification's background color is chosen automatically by the operating system, you cannot modify it manually.
  • The operating system displays notifications. They can remain visible after an end user closes the application.
  • Windows 8-style notifications automatically display a shortcut icon in the bottom-right corner. This icon cannot be removed.
  • The number of notifications that a visible simultaneously depends on the end user's system settings.
  • Windows 10 Anniversary Update (Redstone 1, build 1607) and newer versions support the Generic notification template.

Is this topic helpful?​​​​​​​