Skip to content

The wpf implementation of the system tray icon.

cs
public class NotifyIcon : FrameworkElement, IDisposable

Attributes

PropertyDescriptionDefault ValueRemarks
TokenUsed to set the message markUsed to display the bubble prompt on the specified tray icon
TextMouse prompt text
IconIcon
ContextContentRight click to pop up content
BlinkIntervalBlink Interval500ms
IsBlinkIs it blinkingfalse

Method

NameDescription
Init()Initialization
Register(string, NotifyIcon)Register a message mark for the specified tray icon
Unregister(string, NotifyIcon)Unregister the message mark for the specified tray icon
Unregister(NotifyIcon)If the tray icon is registered with a message mark, cancel the registration
Unregister(string)Unregister if the message is marked with a corresponding tray icon
ShowBalloonTip(string, string, NotifyIconInfoType, string)Show bubble tip
ShowBalloonTip(string, string, NotifyIconInfoType)Show bubble tip
CloseContextControl()Close the context control

Events

NameDescription
ClickTriggered when clicked
MouseDoubleClickTriggered on double click
BalloonTipClicked

Case

xml
<hc:NotifyIcon Text="HandyControl" IsBlink="true" Visibility="Visible" Icon="/HandyControlDemo;component/Resources/Img/icon-white.ico"/>

or

 <hc:NotifyIcon Text="HandyControl">
                <hc:NotifyIcon.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="hc:ControlCommands.PushMainWindow2Top" Header="Open"/>
                        <MenuItem Command="hc:ControlCommands.ShutdownApp" Header="Exit"/>
                    </ContextMenu>
                </hc:NotifyIcon.ContextMenu>
            </hc:NotifyIcon>

or

<hc:NotifyIcon Text="HandyControl" Icon="/HandyControlDemo;component/Resources/Img/icon-white.ico">
                <hc:NotifyIcon.ContextContent>
                    <Border>
                        <StackPanel VerticalAlignment="Center" Margin="16">
                            <Path Width="100" Height="100" Fill="#f06632" Data="{StaticResource LogoGeometry}"/>
                            <StackPanel Margin="0,16,0,0" HorizontalAlignment="Center" Orientation="Horizontal">
                                <Button Click="ButtonPush_OnClick" Command="hc:ControlCommands.PushMainWindow2Top" MinWidth="100" Content="OpenPanel"/>
                                <Button Command="hc:ControlCommands.ShutdownApp" Margin="16,0,0,0" MinWidth="100" Style="{StaticResource ButtonPrimary}" Content="Exit"/>
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </hc:NotifyIcon.ContextContent>
            </hc:NotifyIcon>

NOTE

you can use hc:ControlCommands for exit app or open it. or you can use event instead of it.

cs
private void ButtonPush_OnClick(object sender, RoutedEventArgs e) => NotifyIconContextContent.CloseContextControl();

NotifyIcon

BallonTip

cs
NotifyIcon.ShowBalloonTip("HandyControl", "Hello", NotifyIconInfoType.None, ContextMenuIsShow ? MessageToken.NotifyIconDemo : MessageToken.NotifyIconContextDemo);

Fix dissapear icon from taskbar

If Explorer.exe process restarts or crashs, the notification icon will disappear from the taskbar. To Fix this issue, define the following behavior in the one of hc:Window, hc:BlurWindow, hc:GlowWindow or System.Windows.Window

<hc:Window>
  <hc:NotifyIcon x:Name="NotifyIcon"/>
  <hc:Interaction.Behaviors>
    <hc:TaskbarRebuildBehavior Element="{Binding ElementName=NotifyIcon}" />
  </hc:Interaction.Behaviors>
</hc:Window>

Released under the MIT License.