[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]ViewModels
  [Expand]Commands
  [Expand]Behaviors
  [Collapse]Services
    Getting Started
    Services in ViewModelBase descendants
    Services in POCO objects
    Services in custom ViewModels
    View creation mechanisms
   [Collapse]Predefined Set
    [Expand]Dialog Services
    [Expand]Message Box Services
    [Expand]Document Services
    [Expand]ViewInjectionService
    [Expand]Report Services
     NotificationService
     TaskbarButtonService
     ApplicationJumpListService
     DXSplashScreenService
     DispatcherService
     FrameNavigationService
     LayoutSerializationService
     FolderBrowserDialogService
     OpenFileDialogService
     SaveFileDialogService
     WizardService
     NotifyIconService
    How to create a Custom Service
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[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)

NotificationService

NotificationService is an INotificationService implementation that allows you to show Windows 8 Style notifications.

Assume that you need to notify an end-user about some events in your application. To show the required notifications in Windows 8 style, you can use the NotificationService. Place the NotificationService into the Interaction.Behaviors collection as shown below.

By default, NotificationService uses the native Windows 8 mechanism to show its notifications. An advantage of such notifications is that they can be shown over WinRT applications.

Expanded NotificationService displaying mechanism

To make NotificationService use its own mechanisms, it's necessary to set the NotificationService.UseWin8NotificationsIfAvailable property to false. Otherwise, when the UseWin8NotificationsIfAvailable option is enabled, it's necessary to use an appropriate NotificationService.ApplicationId. This id should be specified in the application shortcut located in the "%APPDATA%\Roaming\Microsoft\Windows\Start Menu\Programs" directory. This is a requirement of the technology. To create a shortcut with the required application id, use our DevExpress.Data.ShellHelper class as shown below.

Next, use the NotificationService from our View Model defined as a POCO object. If View Model is inherited from the ViewModelBase, use the approach from Services in ViewModelBase descendants.

As you can see in the code snippet above, the notification is created via the NotificationService.CreatePredefinedNotification method with four parameters. The number of initialized parameters depends on which NotificationService.PredefinedNotificationTemplate is used by NotificationService. For instance, to fill out all fields in the ShortHeaderAndTwoTextFields template, you need specify the first three parameters. The last parameter is responsible for the image shown within the notification.

Expanded Create a custom notification

It is possible to specify your own notifications with a custom layout. To define a custom layout, use the NotificationService.CustomNotificationTemplate property as follows. Note that in this case, the NotificationService uses its own notifications, since the native mechanism doesn't allow you to define notifications with a custom layout.

To create a custom notification, use the NotificationService.CreateCustomNotification method, which requires a notification View Model as a parameter.

To show the created notification, use the INotification.ShowAsync method. This method returns a NotificationResult enumeration value that depends on how the notification is shown and which element of the notification a user clicks.

  • If a user clicks the displayed notification, the ShowAsync method returns the NotificationResult.Activated value.
  • If a user clicks the notification's close button in the top right corner, the ShowAsync method returns the NotificationResult.UserCanceled value.
  • If the notification or its element wasn't clicked during the time span specified in the NotificationService.CustomNotificationDuration or NotificationService.PredefinedNotificationDuration property, the ShowAsync method returns the NotificationResult.TimedOut value.
  • If the notification was hidden programmatically using the INotification.Hide method, ShowAsync returns the NotificationResult.ApplicationHidden value.
  • If the system's notification queue is full and a new notification cannot be added, ShowAsync returns the NotificationResult.Dropped value.

Below is a code snippet illustrating how to process the result of the ShowAsync method.

Expanded NotificationService sample project

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