Loading...
Loading...
Guide for implementing Syncfusion WPF Toast Notification (SfToastNotification) control for displaying temporary notification messages. Use this skill when implementing toast notifications, pop-up alerts, status messages, or non-intrusive notifications in WPF applications. Covers showing success/error/warning messages, notification systems, and temporary UI feedback without blocking the main window.
npx skill4agent add syncfusion/wpf-ui-components-skills syncfusion-wpf-toast-notificationSfToastNotification.Show()using System.Windows;
using Syncfusion.UI.Xaml.SfToastNotification;
namespace ToastDemo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ShowToast_Click(object sender, RoutedEventArgs e)
{
// Simple toast with title and message
SfToastNotification.Show(this, new ToastOptions
{
Mode = ToastMode.Screen,
Title = "Welcome",
Message = "Hello! This is your first toast notification."
});
}
}
}// Success toast with 8-second duration
SfToastNotification.Show(this, new ToastOptions
{
Title = "Save Successful",
Message = "Your document has been saved successfully.",
Severity = ToastSeverity.Success,
Mode = ToastMode.Screen,
Duration = TimeSpan.FromSeconds(8)
});// Error toast with Retry and Dismiss actions
SfToastNotification.Show(this, new ToastOptions
{
Title = "Operation Failed",
Message = "Unable to save your changes. Please try again.",
Severity = ToastSeverity.Error,
Mode = ToastMode.Screen,
Actions = new List<ToastAction>
{
new ToastAction("Retry")
{
Callback = () => RetryOperation(),
CloseOnClick = true
},
new ToastAction("Dismiss")
{
CloseOnClick = true
}
}
});// App.xaml.cs - Initialize at startup
private void Application_Startup(object sender, StartupEventArgs e)
{
WindowsToastBootstrapper.RemoveShortcutOnUnload = true;
WindowsToastBootstrapper.Initialize("MyApp.App", "MyApplication");
}
// MainWindow.xaml.cs - Show native toast
SfToastNotification.Show(this, new ToastOptions
{
Title = "New Message",
Message = "You have received a new message.",
Mode = ToastMode.Default // Native OS notification
});// Filled variant with custom accent color
SfToastNotification.Show(this, new ToastOptions
{
Title = "Custom Toast",
Message = "This toast uses custom styling.",
Mode = ToastMode.Screen,
Severity = ToastSeverity.Info,
Variant = ToastVariant.Filled,
AccentBrush = new SolidColorBrush(Colors.Purple),
Placement = ToastPlacement.BottomRight,
ShowAnimationType = ToastAnimation.SlideBottomIn,
CloseAnimationType = ToastAnimation.SlideBottomOut
});// Toast remains until user closes it
var options = new ToastOptions
{
Id = "important-notification",
Title = "Important Update",
Message = "Please review this notification carefully.",
Mode = ToastMode.Screen,
Severity = ToastSeverity.Warning,
PreventAutoClose = true // Disable auto-close
};
SfToastNotification.Show(this, options);
// Manually close later by ID
SfToastNotification.Close("important-notification");SfToastNotification.Show(this, new ToastOptions
{
Title = "New Email",
Message = "You have a new message from John Doe.",
Mode = ToastMode.Screen,
Actions = new List<ToastAction>
{
new ToastAction("Reply")
{
Arguments = "Reply",
Callback = () => OpenReplyDialog(),
CloseOnClick = true
},
new ToastAction("Mark as Read")
{
Callback = () => MarkAsRead(),
CloseOnClick = true
},
new ToastAction("Later")
{
CloseOnClick = true
}
}
});| Property | Type | Purpose | Default |
|---|---|---|---|
| Title | string | Bold text at top of toast | null |
| Message | string | Main body text | null |
| Header | string | Additional header (Window/Screen only) | null |
| Mode | ToastMode | Default, Window, or Screen | Default |
| Severity | ToastSeverity | None, Info, Success, Warning, Error | None |
| Variant | ToastVariant | Text, Outlined, Filled | Text |
| Duration | TimeSpan | How long toast stays visible | 6 seconds |
| PreventAutoClose | bool | Disable auto-close | false |
| Placement | ToastPlacement | Screen position (8 options) | TopRight |
| AccentBrush | Brush | Custom color accent | null |
| ShowAnimationType | ToastAnimation | Show animation effect | FadeIn |
| CloseAnimationType | ToastAnimation | Hide animation effect | FadeOut |
| Actions | List<ToastAction> | Interactive action buttons | null |
| ShowActionButtons | bool | Display action button row | true |
| ShowCloseButton | bool | Display close button | true |
| Id | string | Unique identifier for management | null |
SfToastNotification.Show(this, new ToastOptions
{
Title = "Saved",
Message = "Your changes have been saved successfully.",
Severity = ToastSeverity.Success,
Mode = ToastMode.Screen,
Duration = TimeSpan.FromSeconds(4)
});SfToastNotification.Show(this, new ToastOptions
{
Title = "Validation Error",
Message = "Please fill in all required fields before submitting.",
Severity = ToastSeverity.Error,
Mode = ToastMode.Screen,
Placement = ToastPlacement.TopCenter
});SfToastNotification.Show(this, new ToastOptions
{
Title = "Export Complete",
Message = "Your data has been exported to Excel.",
Severity = ToastSeverity.Info,
Mode = ToastMode.Default, // Native OS notification
Actions = new List<ToastAction>
{
new ToastAction("Open File")
{
Callback = () => OpenExportedFile(),
CloseOnClick = true
}
}
});SfToastNotification.Show(this, new ToastOptions
{
Title = "Unsaved Changes",
Message = "You have unsaved changes. Don't forget to save before closing.",
Severity = ToastSeverity.Warning,
Mode = ToastMode.Screen,
Duration = TimeSpan.FromSeconds(10),
Placement = ToastPlacement.BottomCenter
});SfToastNotification.Show(this, new ToastOptions
{
Id = "notification-" + DateTime.Now.Ticks,
Title = "New Message",
Message = $"From: {senderName}\n{messagePreview}",
Severity = ToastSeverity.Info,
Mode = ToastMode.Screen,
Placement = ToastPlacement.BottomRight,
PreventAutoClose = false,
Duration = TimeSpan.FromSeconds(7)
});