How can I help you?
Getting Started with WPF Toast Notification
16 Mar 20269 minutes to read
This section will help you get started with the SfToastNotification control in your WPF application.
Assembly deployment
There are several ways to add Syncfusion® control in to Visual Studio WPF project, the following steps will helps to add a SfToastNotification control
- Create a new WPF project in Visual Studio.
- Add references to the following assemblies:
- Syncfusion.SfToastNotification.WPF
- Syncfusion.Shared.WPF
Alternatively, you can install the Syncfusion.SfToastNotification.WPF NuGet package. This will automatically install all the required dependent assemblies.
Adding WPF SfToastNotification
Since SfToastNotification is a non-UI control, you can create and display toasts entirely through only the C# code, it does not require any XAML configuration.
You can display a basic toast notification with a title and message using the Show method.
using System;
using System.Windows;
using Syncfusion.UI.Xaml.SfToastNotification;
namespace ToastNotificationDemo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// Show a simple information toast from any location in your application
SfToastNotification.Show(this, new ToastOptions
{
Title = "Welcome",
Message = "Hello! This is your first toast notification."
});
}
}
}
NOTE
For displaying default/native toast notifications, you must initialize the WindowsToastBootstrapper for your application in
App.xaml.cs. This initialization is required for the OS level toast to work. Please refer to the Application Startup Configuration section to know more.
The following properties allow you to set the textual content of the toast notification.
- Title: Represents the bold text displayed at the top of the toast. This is typically used to summarize the purpose of the notification.
- Message: Defines the main body text of the toast. This is the primary content that conveys the notification’s information.
-
Header: Specifies an additional header displayed above or beside the message.
This property applies only to in-app toast modes (Window and Screen) and is ignored in native (Default) mode.
Toast Modes
The SfToastNotification control supports three different display modes to suit various application scenarios.
1. Default Mode
Uses the native operating system toast notifications. Ideal for applications that want to integrate with the OS notification system.
Application Startup Configuration
Import the control namespace Syncfusion.UI.Xaml.SfToastNotification in App.xaml.cs and initialize the WindowsToastBootstrapper in the Application_Startup event, as the SfToastNotification is a non-UI control that must be initialized during application startup.
using System.Windows;
using Syncfusion.UI.Xaml.SfToastNotification;
namespace ToastNotificationDemo
{
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
// Initialize the Toast Notification bootstrapper
WindowsToastBootstrapper.RemoveShortcutOnUnload = true;
WindowsToastBootstrapper.Initialize("ToastNotificationDemo.App", "ToastNotificationDemo");
}
}
}Configure the Application_Startup event in App.xaml.
<Application x:Class="ToastNotificationDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>Characteristics:
- Native OS appearance and behavior
- System-level notifications
- Limited customization options
- Best for critical system messages
NOTE
When
ToastMode = Default, No customizations are applicable. The toast uses native OS styling and behavior. Default mode does not accept any customization. This native toast supports only for windows 10 or higher versions.
2. Window Mode
Displays toast notifications within the owning window. Perfect for applications where you want toasts to stay within the application boundaries.
SfToastNotification.Show(this, new ToastOptions
{
Title = "Window Toast",
Message = "This notification appears within the window",
Mode = ToastMode.Window
});Characteristics:
- Constrained to window boundaries
- Full customization support
- Respects window activation state
- Good for application-specific feedback
3. Screen Mode
Displays custom toast overlay globally across the screen. Useful for application-wide notifications that should be visible regardless of window focus.
SfToastNotification.Show(this, new ToastOptions
{
Title = "Global Notification",
Message = "This notification appears globally on screen",
Mode = ToastMode.Screen
});Characteristics:
- Global screen-level display
- Full customization capabilities
- Visible regardless of window state
- Best for important application-wide events
NOTE
The Window and Screen modes are in-app modes and support extensive customization. The Default (native) mode integrates with the operating system and therefore supports only limited customization.
Duration
You can use the Duration property to specify how long the toast remains visible. The default display duration is 6 seconds.
// Toast with 10 second duration
SfToastNotification.Show(this, new ToastOptions
{
Title = "Processing",
Message = "Your request is being processed...",
Mode = ToastMode.Screen,
Duration = TimeSpan.FromSeconds(10)
});Toast without Auto-Close
You can control whether a toast closes automatically by using the PreventAutoClose property.
// Toast remains until user closes it manually
SfToastNotification.Show(this, new ToastOptions
{
Title = "Important",
Message = "Please review this important notification.",
Mode = ToastMode.Screen,
PreventAutoClose = true
});Action Button
You can set whether the action button row is visible in the toast by using the ShowActionButtons property. The default value is true, which displays the action buttons for in-app toasts modes (Window and Screen).
// Toast with-out action buttons
SfToastNotification.Show(this, new ToastOptions
{
Title = "New Notification",
Header = "Updates",
Message = "Your project has been synchronized successfully.",
Mode = ToastMode.Screen,
ShowActionButtons = false
});
Close Button
You can use the ShowCloseButton property to specify whether the close button is visible for the toast. The close button is available only in in-app toasts (Window and Screen modes). The default value is true.
// Toast with the close button hidden
SfToastNotification.Show(this, new ToastOptions
{
Title = "Reminder",
Message = "This toast has its close button disabled.",
Mode = ToastMode.Screen,
ShowCloseButton = false
});
Toast Life cycle
Understanding the life cycle of a toast helps in managing notifications effectively.
States
- Creation - Toast is created with ToastOptions
- Display - Toast appears on screen according to placement and mode
- Duration - Toast remains visible for specified duration
- Dismissal - Toast closes via auto-close timeout, close button, or programmatic close
Managing Toast Life cycle
// Create a toast with custom ID
var options = new ToastOptions
{
Id = "unique-toast-id",
Title = "Tracked Toast",
Message = "This toast can be managed",
Mode = ToastMode.Screen,
Duration = TimeSpan.FromSeconds(10)
};
SfToastNotification.Show(this, options);
// Manually close specific toast
SfToastNotification.Close("unique-toast-id");
// Close all toasts
SfToastNotification.CloseAll();Theme
SfToastNotification supports various built-in themes. Refer to the below links to apply themes for the Badge,
