WpfNotifications 1.0.0.1

dotnet add package WpfNotifications --version 1.0.0.1
                    
NuGet\Install-Package WpfNotifications -Version 1.0.0.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="WpfNotifications" Version="1.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WpfNotifications" Version="1.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="WpfNotifications" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WpfNotifications --version 1.0.0.1
                    
#r "nuget: WpfNotifications, 1.0.0.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.
#:package WpfNotifications@1.0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WpfNotifications&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=WpfNotifications&version=1.0.0.1
                    
Install as a Cake Tool

Notifications

WPF toast notifications.

演示

PixPin_2024-12-29_22-39-32

安装

Install-Package WpfNotifications

使用

  • 修改你的App.xaml 文件。*注意:ShutdownMode="OnMainWindowClose" 此设置防止程序无法正常关闭。

<Application x:Class="Notifications.Sample.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             ShutdownMode="OnMainWindowClose"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Notifications;component/Styles/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

  • 在需要显示通知的地方放置ntf:NotificationArea 并且设置Identifier
            <ntf:NotificationArea Identifier="main_window"
                                  NotificationMargin="10 10 10 0"
                                  MaxItems="3"/>

  • 指定Identifier显示通知
            notificationManager.Show("title", "main_window");
  • 也可传入自定义控件,显示自定义UI的通知
            UserControlMessage userControlMessage = new UserControlMessage();
            notificationManager.Show(userControlMessage, "main_window",false);
  • 在自定义控件中,可继承Notification监听ntf:Notification.NotificationClosing路由事件,获取ExpirationTime值以设置倒计时条.
  • 在自定义控件中,可以自定义设置Width``Height来控制通知的宽高。
<ntf:Notification x:Class="Notifications.Sample.Messages.InformationMessage"
                  ............
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  xmlns:ntf="https://github.com/notifications/xaml/controls"
                  mc:Ignorable="d"
                  Width="300"
                  Height="100"
                  Name="notification"
                  d:DesignHeight="100"
                  d:DesignWidth="300">
    <ntf:Notification.Triggers>
        <EventTrigger RoutedEvent="ntf:Notification.NotificationClosing">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="colorBar"
                                     Storyboard.TargetProperty="Width"
                                     To="0"
                                     Duration="{Binding ElementName=notification, Path=ExpirationTime}" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </ntf:Notification.Triggers>
    ............
</ntf:Notification>

在继承ntf:Notification后,可设置按钮在Csharp代码中控制通知的关闭

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net9.0-windows7.0 is compatible.  net10.0-windows was computed. 
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • net6.0-windows7.0

    • No dependencies.
  • net7.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.
  • net9.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.1 541 12/30/2024
1.0.0 133 12/29/2024