Notifications.Wpf.Core 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Notifications.Wpf.Core --version 1.3.1                
NuGet\Install-Package Notifications.Wpf.Core -Version 1.3.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.3.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.3.1                
#r "nuget: Notifications.Wpf.Core, 1.3.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.3.1

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

Notifications.Wpf.Core

Version Downloads

Toast notifications for WPF apps based on .NET Core 3.1

This is a fork of Notifications.Wpf

Demo

Installation:

Install-Package Notifications.Wpf.Core

Usage:

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

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

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 Name property directly does not work, we offer you the BindableName property instead.

<notifications:NotificationArea
    BindableName="{Binding NotificationAreaIdentifier}"
    MaxItems="3"
    Position="TopRight" />
  • Displaying notification:
await notificationManager.ShowAsync(
                new NotificationContent {Title = "Notification", Message = "Notification in window!"},
                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: (identifier) => {
    NotifySomeoneAboutClose(identifier);
});

await notificationManager.CloseAsync(identifier);

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 net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • 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
2.0.1 220 11/8/2024
1.4.1 15,918 9/26/2022
1.4.0 3,863 2/25/2022
1.3.2 16,515 10/13/2020
1.3.1 1,537 7/15/2020
1.2.0 4,144 1/5/2020
1.1.2 930 11/27/2019
1.1.1 848 11/26/2019
1.1.0 876 11/26/2019