Repository navigation
Toast Notifications
Toast Notification implemented: Success, Information, Warning, Error. How it works? It's easy.
- Inject
INotificationManagerinto your ViewModel constructor:public partial class MainWindowsViewModel : ViewModelBase, IDisposable { private readonly INotificationManager _notificationManager; public MainWindowsViewModel(INotificationManager notificationManager) { _notificationManager = notificationManager; } // ... other code... }
- Create a toast message:
var errorToast = NotificationManager.CreateErrorToast("Message text", "Title"); // or var successToast = NotificationManager.CreateSuccessToast("Message text", "Title"); // or var warningToast = NotificationManager.CreateWarningToast("Message text", "Title"); // or var informationToast = NotificationManager.CreateInformationToast("Message text", "Title");
- The show a toast:
_notificationManager.Show(errorToast); // or _notificationManager.Show(successToast); // or _notificationManager.Show(warningToast); // or _notificationManager.Show(informationToast);
- There are two zone where you can show a toasts:
-
Screen- All toast notifications will show on the screen outside of the application. In this case you do not do anything. This case already works "out of the box". -
NotificationZone- All toast notification will show in the special controlNotificationZoneyou should add on your XAML (VisualTree). You can do this something like shown below:Add namespace first
xmlns:controls="clr-namespace:Calabonga.Commandex.Engine.ToastNotifications.Controls;assembly=Calabonga.Commandex.Engine"
Then add control
NotificationZonewith name "NotificationZone":<controls:NotificationZone x:Name="NotificationZone" ItemsCountMax="3" Position="TopRight" />
After than you should add a
NotificationZoneas a parameter forShow()method:_notificationManager.Show(errorToast, "NotificationZone"); // or _notificationManager.Show(successToast, "NotificationZone"); // or _notificationManager.Show(warningToast , "NotificationZone"); // or _notificationManager.Show(informationToast, "NotificationZone");
-
There are many windows created when you are use Toast Notifications. That's why when you close main window of the application the process not exit. Please use this solution to close you application correctly.
In MainWindow of your App add this:
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Application.Current.Shutdown();
}