####Toast notifications for Wpf with MVVM support. ToastNotifications allows you to show Success, Information, Warning and Error animated notifications, which will disappear after several seconds.
Feel free to modify and use this code with MIT license.
##Demo:
Install via Nuget Package ToastNotifications
Install-Package ToastNotifications
##Usage
<!- import namespace -->
xmlns:toastNotifications="clr-namespace:ToastNotifications;assembly=ToastNotifications"
<!- add NotificationTray to place in view where notifications should appear and make binding to NotificationsSource in viewmodel -->
<toastNotifications:NotificationTray NotificationsSource="{Binding NotificationSource}"
VerticalAlignment="Top"
HorizontalAlignment="Right" />
// Create viewmodel for window with property of type NotificationsSource.
// NotificationsSource is used to show nofifications in ToastNotifications control
public class MainViewModel : INotifyPropertyChanged
{
private NotificationsSource _notificationSource;
public NotificationsSource NotificationSource
{
get { return _notificationSource; }
set
{
_notificationSource = value;
OnPropertyChanged("NotificationSource");
}
}
public MainViewModel()
{
NotificationSource = new NotificationsSource();
}
public void ShowInformation(string message)
{
NotificationSource.Show(message, NotificationType.Information);
}
public void ShowSuccess(string message)
{
NotificationSource.Show(message, NotificationType.Success);
}
public void ShowWarning(string message)
{
NotificationSource.Show(message, NotificationType.Warning);
}
public void ShowError(string message)
{
NotificationSource.Show(message, NotificationType.Error);
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
####Configuration ######Flow direction Set direction in which new notifications will appear. It's relative to notification control position. Avalaible options are:
- LeftDown (default)
- RightDown
- LeftUp
- RightUp
<toastNotifications:NotificationTray PopupFlowDirection="LeftDown" />
######Notification source properties
public MainViewModel()
{
NotificationSource = new NotificationsSource
{
MaximumNotificationCount = 4,
NotificationLifeTime = TimeSpan.FromSeconds(3)
};
}
##Contributors Uwy (https://github.com/Uwy)
Andy Li (https://github.com/oneandy)