** Este proyecto es una continuación del proyecto base inactivo para otras plataformas (WinUI/Uno.Skia.Wpf/Console) - https://github.com/hardcodet/wpf-notifyicon **
Esta es una implementación de NotifyIcon (también conocido como ícono de la bandeja del sistema o ícono de la barra de tareas) para plataformas .Net 6 WPF/WinUI/Uno.Skia.WPF/Console. No solo se basa en el componente NotifyIcon de Windows Forms, sino que es un control puramente independiente que aprovecha varias características de los marcos WPF/WinUI para mostrar información sobre herramientas enriquecida, ventanas emergentes, menús contextuales y mensajes de globo. Puede usarse directamente en el código o incrustarse en cualquier archivo XAML.
Install-Package H.NotifyIcon.Wpf
Install-Package H.NotifyIcon.WinUI
Install-Package H.NotifyIcon.Uno
Install-Package H.NotifyIcon.Uno.WinUI
# If you need other platforms, you can use this Core library -
# it allows you to make NotifyIcon even in a console application.
Install-Package H.NotifyIcon
< Window
xmlns : tb = " clr-namespace:H.NotifyIcon;assembly=H.NotifyIcon.Wpf " // WPF
xmlns : tb = " using:H.NotifyIcon " // WinUI
>
< tb : TaskbarIcon
ToolTipText = " ToolTip "
IconSource = " /Images/TrayIcons/Logo.ico "
ContextMenu = " {StaticResource TrayMenu} "
MenuActivation = " LeftOrRightClick "
TrayPopup = " {StaticResource TrayStatusPopup} "
PopupActivation = " DoubleClick "
TrayToolTip = " {StaticResource TrayToolTip} "
/>
</ Window >
Windows 11 introduce un nuevo concepto llamado Modo de eficiencia.
Dado que, básicamente, esta biblioteca está destinada a que existan aplicaciones en segundo plano con la capacidad de interactuar a través de TrayIcon, la biblioteca implementa una API para este modo:
EfficiencyModeUtilities . SetEfficiencyMode ( bool value )
WindowExtensions . Hide ( this Window window , enableEfficiencyMode : true ) // default value
WindowExtensions . Show ( this Window window , disableEfficiencyMode : true ) // default value
TaskbarIcon . ForceCreate ( bool enablesEfficiencyMode = true ) // default value
Ejemplo 1:
< tb : TaskbarIcon >
< tb : TaskbarIcon .IconSource>
< tb : GeneratedIconSource
Text = " "
Foreground = " Red "
/>
</ tb : TaskbarIcon .IconSource>
</ tb : TaskbarIcon >
Ejemplo 2:
< tb : TaskbarIcon
IconSource = " /Icons/Error.ico "
>
< tb : TaskbarIcon .IconSource>
< tb : GeneratedIconSource
Text = " 5 "
Foreground = " Black "
FontSize = " 36 "
FontWeight = " Bold "
/>
</ tb : TaskbarIcon .IconSource>
</ tb : TaskbarIcon >
Ejemplo 3:
< tb : TaskbarIcon >
< tb : TaskbarIcon .IconSource>
< tb : GeneratedIconSource
Text = " "
Foreground = " Red "
FontFamily = " Segoe UI Emoji "
Background = " AliceBlue "
FontWeight = " Bold "
FontSize = " 38 "
/>
</ tb : TaskbarIcon .IconSource>
</ tb : TaskbarIcon >
Ejemplo 4:
< tb : TaskbarIcon >
< tb : TaskbarIcon .IconSource>
< tb : GeneratedIconSource
Text = " "
BorderThickness = " 5 "
FontSize = " 46 "
>
< tb : GeneratedIconSource .Foreground>
< LinearGradientBrush StartPoint = " 0,0 " EndPoint = " 128,128 " >
< GradientStop Color = " White " />
< GradientStop Color = " Red " />
</ LinearGradientBrush >
</ tb : GeneratedIconSource .Foreground>
< tb : GeneratedIconSource .BorderBrush>
< LinearGradientBrush StartPoint = " 0,0 " EndPoint = " 128,128 " >
< GradientStop Color = " White " />
< GradientStop Color = " Red " />
</ LinearGradientBrush >
</ tb : GeneratedIconSource .BorderBrush>
</ tb : GeneratedIconSource >
</ tb : TaskbarIcon .IconSource>
</ tb : TaskbarIcon >
Se recomienda fijar el ícono del diseñador para verlo fácilmente. Para hacer esto, vaya a Configuración de la barra de tareas -> Otros íconos de la bandeja del sistema y habilite este ícono:
Por el momento, se implementan tres modos, cada uno con sus pros y sus contras.
Disponibilidad de varias opciones (depende de la versión de WindowsAppSDK
que esté utilizando):
Opción | Aplicación empaquetada | Aplicación sin empaquetar |
---|---|---|
Transparencia | desde 1.1.0-vista previa | desde 1.1.0-vista previa |
Sin fronteras | desde 1.1.0-vista previa | |
Animaciones | , pero con fronteras | desde 1.1.0-vista previa |
Submenús |
Lugar prioritario para errores: https://github.com/HavenDV/H.NotifyIcon/issues Lugar prioritario para ideas y preguntas generales: https://github.com/HavenDV/H.NotifyIcon/discussions También tengo un Discord canal de soporte:
https://discord.gg/g8u2t9dKgE