WPF 将软件最小化最托盘,右键点击托盘图标可弹出菜单
nuget包中引用HandyControl
在主窗体中引入xmlns:hc="https://handyorg.github.io/handycontrol"
在主窗体中加入代码
<Window.Resources>
<ContextMenu x:Key="ContextMenu">
<MenuItem Click="MenuItem_Click" Header="开机自启"/>
<Separator></Separator>
<MenuItem Click="MenuItem_Click_1" Header="最小化到托盘" />
<MenuItem Click="MenuItem_Click_2" Header="退出软件"/>
</ContextMenu>
</Window.Resources>
<Grid>
<hc:NotifyIcon x:Name="NotifyIconContextContent"
Text="软件名称"
ContextMenu="{StaticResource ContextMenu}"
Visibility="Collapsed"
Icon="/软件logo.ico">
<hc:Interaction.Triggers>
<hc:EventTrigger EventName="Click">
<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>
</hc:EventTrigger>
</hc:Interaction.Triggers>
</hc:NotifyIcon>
</Grid>
效果