Skip to content

ConquestSolutions/ToastNotifications

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToastNotifications

####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.

Build status Nuget install MIT license

##Demo:

demo

Install-Package ToastNotifications

##Usage

xaml
<!- 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" />
csharp
// 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)

About

Toast notifications for Wpf

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%