Notifications.Wpf.Core 1.4.1

dotnet add package Notifications.Wpf.Core --version 1.4.1
NuGet\Install-Package Notifications.Wpf.Core -Version 1.4.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Notifications.Wpf.Core" Version="1.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Notifications.Wpf.Core --version 1.4.1
#r "nuget: Notifications.Wpf.Core, 1.4.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Notifications.Wpf.Core as a Cake Addin
#addin nuget:?package=Notifications.Wpf.Core&version=1.4.1

// Install Notifications.Wpf.Core as a Cake Tool
#tool nuget:?package=Notifications.Wpf.Core&version=1.4.1

Notifications.Wpf.Core

Version Downloads

Toast notifications for WPF apps based on .NET 6

This is a fork of Notifications.Wpf

Demo

Installation:

Install-Package Notifications.Wpf.Core

Usage:

Notification over the taskbar:
var notificationManager = new NotificationManager();

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

await notificationManager.ShowAsync(notificationContent);

You can also alter this position by passing the desired position as an argument

var notificationManager = new NotificationManager(NotificationPosition.TopRight);
Notification inside application window:
  • Adding namespace:
xmlns:notifications="clr-namespace:Notifications.Wpf.Core.Controls;assembly=Notifications.Wpf.Core"
  • Adding new NotificationArea:
<notifications:NotificationArea  
     MaxItems="3"
     x:Name="WindowArea"
     Position="TopLeft" />

It is also possible to add the area name with a Binding. But as binding to the Name property directly does not work, we offer you the BindableName property instead.

<notifications:NotificationArea
    BindableName="{Binding NotificationAreaIdentifier}"
    MaxItems="3"
    Position="TopRight" />
  • Displaying notification:
var notificationContent = new NotificationContent
{
    Title = "Notification",
    Message = "Notification in window!"
};

await notificationManager.ShowAsync(notificationContent, areaName: "WindowArea");
Simple text with OnClick & OnClose actions:
await notificationManager.ShowAsync("String notification",
    onClick: () => Console.WriteLine("Click"),
    onClose: () => Console.WriteLine("Closed!")
);
Notifications with identifiers

Sometimes it comes in handy if you can close specific notifications via code. To do that you have the possibility to specify an identifier in the form of a Guid for a notification.


var identifier = Guid.NewGuid();

await notificationManager.ShowAsync(identifier,
        "I'm here to stay",
        expirationTime: TimeSpan.MaxValue,
        onClose: (id) =>
        {
            NotifySomeoneAboutClose(id);
        });

await notificationManager.CloseAsync(identifier);
Adjust style of notificiations

You do not like the default styles of the notifications? No problem. You can use your own custom styles. Take a look the sample project Notifications.Wpf.Core.Sample where this is demonstrated. Basically you have to create a custom NotificationTemplateSelector in which you specify which templates should be used.

Caliburn.Micro MVVM support:

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

<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>
  • NotificationViewModel:

The used view model must implement INotificationViewModel

public class NotificationViewModel : PropertyChangedBase, INotificationViewModel
{
    private readonly INotificationManager _manager;

    private Guid? _notificationIdentifier;

    public string? Title { get; set; }
    public string? Message { get; set; }

    public NotificationViewModel(INotificationManager manager)
    {
        _manager = manager;
    }
        
    // This method is called when the notification with this view/view model is
    // shown. It can be used to receive the identifier of the notification
    public void SetNotificationIdentifier(Guid identifier)
    {
        _notificationIdentifier = identifier;
    }

    public async Task Ok()
    {
        await Task.Delay(500);
        await _manager.ShowAsync(new NotificationContent { Title = "Success!", 
                  Message = "Ok button was clicked.", Type = NotificationType.Success });
    }

    public async Task Cancel()
    {
        await Task.Delay(500);
        await _manager.ShowAsync(new NotificationContent { Title = "Error!", 
                  Message = "Cancel button was clicked!", Type = NotificationType.Error });
    }
}
  • ShellViewModel:
var content = new NotificationViewModel(_manager)
{
    Title = "Custom notification.",
    Message = "Click on buttons!"
};

await _manager.ShowAsync(content, expirationTime: TimeSpan.FromSeconds(30));
  • NotificationView:
<DockPanel LastChildFill="False">
    
    <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

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Notifications.Wpf.Core:

Package Downloads
MicroCloud.Wpf

MicroCloud Wpf 客户端应用组件,封装基于Stylet的Wpf客户端的核心组件。

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Notifications.Wpf.Core:

Repository Stars
dotnetcore/osharp
OSharp是一个基于.Net6.0的快速开发框架,框架对 AspNetCore 的配置、依赖注入、日志、缓存、实体框架、Mvc(WebApi)、身份认证、功能权限、数据权限等模块进行更高一级的自动化封装,并规范了一套业务实现的代码结构与操作流程,使 .Net 框架更易于应用到实际项目开发中。
WolvenKit/CyberCAT
CyberPunk 2077 Customization Assistant Tool. Work in progress Savegame editor.
Version Downloads Last updated
1.4.1 11,880 9/26/2022
1.4.0 3,785 2/25/2022
1.3.2 16,219 10/13/2020
1.3.1 1,494 7/15/2020
1.2.0 4,093 1/5/2020
1.1.2 883 11/27/2019
1.1.1 808 11/26/2019
1.1.0 844 11/26/2019