Skip to content

Federerer/Notifications.Wpf

Repository files navigation

Notifications.Wpf

WPF toast notifications.

Demo

Installation:

Install-Package Notifications.Wpf

Usage:

Notification over the taskbar:

var notificationManager = new NotificationManager();

notificationManager.Show(new NotificationContent
           {
               Title = "Sample notification",
               Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
               Type = NotificationType.Information
           });

Notification inside application window:

  • Adding namespace:
xmlns:notifications="clr-namespace:Notifications.Wpf.Controls;assembly=Notifications.Wpf"
  • Adding new NotificationArea:
<notifications:NotificationArea x:Name="WindowArea" Position="TopLeft" MaxItems="3"/>
  • Displaying notification:
notificationManager.Show(
                new NotificationContent {Title = "Notification", Message = "Notification in window!"},
                areaName: "WindowArea");

Simple text with OnClick & OnClose actions:

notificationManager.Show("String notification", onClick: () => Console.WriteLine("Click"),
               onClose: () => Console.WriteLine("Closed!"));

Caliburn.Micro MVVM support:

  • App.xaml:
xmlns:controls="clr-namespace:Notifications.Wpf.Controls;assembly=Notifications.Wpf"

<Application.Resources>
    [...]
    <Style TargetType="controls:Notification">
        <Style.Resources>
            <DataTemplate DataType="{x:Type micro:PropertyChangedBase}">
                <ContentControl cal:View.Model="{Binding}"/>
            </DataTemplate>
        </Style.Resources>
    </Style>
</Application.Resources>
  • ShellViewModel:
var content = new NotificationViewModel(_manager)
{
    Title = "Custom notification.",
    Message = "Click on buttons!"
};

_manager.Show(content, expirationTime: TimeSpan.FromSeconds(30));
  • NotificationView:
<DockPanel LastChildFill="False">
    <!--Using CloseOnClick attached property to close notification when button is pressed-->
    <Button x:Name="Ok" Content="Ok" DockPanel.Dock="Right" controls:Notification.CloseOnClick="True"/>
    <Button x:Name="Cancel" Content="Cancel" DockPanel.Dock="Right" Margin="0,0,8,0" controls:Notification.CloseOnClick="True"/>
</DockPanel>
  • Result:

Demo

About

Toast notifications for WPF

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published