H.NotifyIcon
1.0.0
** 本專案是非活動基礎專案到其他平台 (WinUI/Uno.Skia.Wpf/Console) 的延續 - https://github.com/hardcodet/wpf-notifyicon **
這是 .Net 6 WPF/WinUI/Uno.Skia.WPF/Console 平台的 NotifyIcon(又稱系統托盤圖示或工作列圖示)的實作。它不僅依賴 Windows 窗體 NotifyIcon 元件,而且是一個完全獨立的控件,它利用 WPF/WinUI 框架的多個功能來顯示豐富的工具提示、彈出視窗、上下文選單和氣球訊息。它可以直接在程式碼中使用,也可以嵌入任何 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 引進了一個稱為效率模式的新概念。
基本上,該庫旨在讓應用程式存在於後台並能夠透過 TrayIcon 進行交互,因此該庫為此模式實現了一個 API:
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
範例1:
< tb : TaskbarIcon >
< tb : TaskbarIcon .IconSource>
< tb : GeneratedIconSource
Text = " "
Foreground = " Red "
/>
</ tb : TaskbarIcon .IconSource>
</ tb : TaskbarIcon >
範例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 >
範例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 >
範例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 >
建議固定設計器圖示以方便查看。為此,請前往工作列設定 -> 其他系統托盤圖示並啟用此圖示:
目前實施了三種模式,每種模式都有自己的優點和缺點。
各種選項的可用性(取決於您使用的WindowsAppSDK
版本):
選項 | 打包應用程式 | 未打包的應用程式 |
---|---|---|
透明度 | 從 1.1.0 預覽版開始 | 從 1.1.0 預覽版開始 |
無邊框 | 從 1.1.0 預覽版開始 | |
動畫 | ,但有邊框 | 從 1.1.0 預覽版開始 |
子選單 |
錯誤的優先位置:https://github.com/HavenDV/H.NotifyIcon/issues 想法和一般問題的優先位置:https://github.com/HavenDV/H.NotifyIcon/discussions 我也有一個 Discord支援通路:
https://discord.gg/g8u2t9dKgE