WPF NotifyIcon
This is an implementation of a NotifyIcon (aka system tray icon or taskbar icon) for the WPF platform. It does not just rely on the Windows Forms NotifyIcon component, but is a purely independent control which leverages several features of the WPF framework in order to display rich ToolTips, Popups, context menus, and balloon messages. It can be used directly in code or embedded in any XAML file.

Download Control & Sample Application
(Latest release: 1.0.4, 2009.09.22)
Features at a glance
- Custom Popups (interactive controls) on mouse clicks.
- Customized ToolTips (Vista and above) with fallback mechanism for xp/2003.
- Rich event model including attached events to trigger animations in Popups, ToolTips, and balloon messages. I just love that.
- Full support for standard Windows balloons, including custom icons.
- Custom balloons that pop up in the tray area. Go wild with styles and animations
- Support for WPF context menus.
- You can define whether to show Popups on left-, right-, double-clicks etc. The same goes for context menus.
- Simple data binding for Popups, ToolTips and custom balloons through attached properties and derived data context.
- Command support for single / double clicks on the tray icon.
Tutorial and Support
- A comprehensive tutorial that complements the attached sample application can be found on the Code Project:
http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx
Please post support questions to the CodeProject forum only. Thank you.
Screenshots
The screenshots below were taken from NetDrives and the sample application.





XAML Declaration Sample
The sample below shows some of the properties of the control. For a more comprehensive sample, have a look at the sample application that comes with the download.
<Window x:Class="Hardcodet.NetDrives.UI.SystemTray.Sample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:tb="http://www.hardcodet.net/taskbar"> <tb:TaskbarIcon x:Name="myNotifyIcon" Visibility="Visible" ToolTipText="Fallback ToolTip for Windows xp" IconSource="/Images/TrayIcons/Logo.ico" ContextMenu="{StaticResource TrayMenu}" MenuActivation="LeftOrRightClick" TrayPopup="{StaticResoure TrayStatusPopup}" PopupActivation="DoubleClick" TrayToolTip="{StaticResource TrayToolTip}" /> </Window>
Philipp - Nice work. Quick question. Is there an easy way to just use this as a nice tooltip replacement to get balloon tips on any WPF object? (Paths in my case and I need to do in in the code behind)
I am creating ToolTips programmatically and then calling ToolTipService.SetShowOnDisabled to assign them to my Paths. It would be nice to do something similar with your Balloon popup! Any way to do so?
James,
The balloons are also just standard popups - you can display them for any control by just setting the PlacementTarget - just check their usage in the control, which is pretty trivial.
Cheers,
Philipp
Hi,
Great control, thanks for your efforts.
I made a small modification. I found the positioning of context menu and custom popup a little odd. I am surprised nobody else has seen this. Maybe its because I use two screens. However, changing the placement to PlacementMode.MousePoint mad it work much better:
/*
//use absolute position
ContextMenu.Placement = PlacementMode.AbsolutePoint;
ContextMenu.HorizontalOffset = cursorPosition.X;
ContextMenu.VerticalOffset = cursorPosition.Y;
*/
// FIX: use mousepoint as the positioning - works better
ContextMenu.Placement = PlacementMode.MousePoint;
Vista built-in system tray icons like Power, Date/Time, Volume, Network had rich tooltips with icons but Windows 7 has plain tooltips for system tray icons. Can you bring rich tooltips for system icons on Windows 7?
@Christian
Hi Christian, when compiling for c# 4.0 you can fix the “No constructor for type ‘HideSampleWindowsCommand’ has 0 parameters.” warnings by adding default constructors to the ShowSampleWindowCommand and HideSampleWindowsCommand classes (e.g. “public HideSampleWindowCommand() : base(){}”). However there is at least one other problem with the C# 4.0 version, you can see it by starting the same project, “Open sample Window” then right click the tray icon for the context menu - Options “Show/Hide Context Menu” are permanently greyed out, and the tooltips text is no longer visible (tested under Win XP VS2010 C# V4.0). Still trying to work out why, any tips appreciated, thanks.
Keith and others
I’ll look at theses issues with C# 4.0 asap and post back.
Cheers,
Philipp
Hi. I found this topic on CodeProject but since yesterday did not get any suggestions on trigger error. It seems that I misunderstood something in WPF/XAML but I can’t get to work this simply case. I’d like to run trigger by checking context menu attached to notify icon. Sample code yo may find at Your article discussion at CodeProject here - http://www.codeproject.com/Messages/3848077/Re-How-about-triggers-in-ContextMenu.aspx
I would appreciate any comments and suggestions. And thanx for great work!
Many, many thanks for your library! It helped me a lot. I have one question — you can set animation for you custom balloon, for example as slide. Is there any way to set animation for “closing” the balloon — I would like to slide it down (exactly speaking: to slide it down on timeout, to close it on user manual close). Thank you in advance for figuring it out.
Still no suggestions?
Hi
Very cool library. We use it in Nemo Documents and so far it’s really great. There is just one little problem that we get once in a while, the “Could not create icon data” exception.
As can be seen here:
http://msdn.microsoft.com/en-us/library/bb762159%28v=vs.85%29.aspx
It appears to be related to startup. But I have tried doing a the try and sleep and bit before trying again for a couple of times. This took away quite a bit of them, but there are still some left.
Looking comments in that microsoft article, maybe it would be a good idea to hook into the WM_CREATE event? That way it would also work if explorer crashed and is restarted.
I tried setting the icon for TaskBarIcon
Sample Code :
but it gives me this error, I think I already set the icon correctly but still error occurs
Error : Provide value on ‘System.Windows.Baml2006.TypeConverterMarkupExtension
Any ideas?
Hi,
I was trying to use the notifyicon for a project i’m working on.
I came across a bug, to reproduce:
- End process “explorer.exe”.
- Start your program which uses the notifyicon (or start your project in visual studio).
- Start process “explorer.exe”.
This problem also occurres when a user with a large roaming profile logs on and the program with the notifyicon starts when windows starts. At this time, explorer is not fully started until the user’s profile is loaded.
@Chris Baker
Make sure you’ve set your Application’s ShutdownMode to OnMainWindowClose. By default it’s set to LastWindowClosed and since the notify icon creates a window, it will keep your application alive after the main window closes and you’ll have to kill it from the task manager.
Hi Philipp,
I’ve downloaded your WPF NotifyIcon and is great control.
I’m a new WPF coder, learning the MVVM pattern.
In my application i’m trying to bind a context menu to a command that i’ve created.
In a resource file, i’ve created the taskBarIcon and the context menu.
Here is how, i’m creating the TaskBarIcon and the context menu:
Here is my base class for commands:
public class ViewModelCommand : ICommand
{
public ViewModelCommand(Action executeAction,
Predicate canExecute)
{
if (executeAction == null)
throw new ArgumentNullException(”executeAction”);
_executeAction = executeAction;
_canExecute = canExecute;
}
private readonly Predicate _canExecute;
public bool CanExecute(object parameter)
{
if (_canExecute == null) return true;
return _canExecute(parameter);
}
public event EventHandler CanExecuteChanged;
public void OnCanExecuteChanged()
{
if (CanExecuteChanged != null)
CanExecuteChanged(this, EventArgs.Empty);
}
private readonly Action _executeAction;
public void Execute(object parameter)
{
_executeAction(parameter);
}
}
Here is the viewmodel code for my main window
public class MainViewModel : ViewModel
{
public DataClient dataClient;
public TaskbarIcon taskBarIcon;
private ViewModelCommand fCheckSomethingOnServer = null;
public ViewModelCommand CheckSomethingOnServer
{
get
{
if (fCheckSomethingOnServer == null)
{
fCheckSomethingOnServer = new ViewModelCommand(p => CheckSomething(this, new CheckSomethingEventArgs(dataClient)), p => CanCheckSomething);
}
return fCheckSomethingOnServer;
}
}
public class CheckSomethingEventArgs : EventArgs
{
public CheckSomethingEventArgs(DataClient dataClient)
{
this.dataClient = dataClient;
}
public DataClient dataClient { get; set; }
}
private void CheckSomething(object sender, CheckSomethingEventArgs e)
{
e.DataClient.CheckSomething();
}
private bool CanCheckSomething
{
get { return dataClient.Logged; }
}
}
Here is the Main Window code:
public DataClient dataClient;
private TaskbarIcon tb;
private MainViewModel _viewModel = null;
public MainWindow()
{
InitializeComponent();
dataClient = new DataClient();
tb = (TaskbarIcon)FindResource(”MyNotifyIcon”);
if (fViewModel == null)
{
fViewModel = new MainViewModel();
fViewModel.dataClient = dataClient;
fViewModel.taskBarIcon = tb;
DataContext = fViewModel;
}
}
The problem is that the CheckSomethingOnServer command is never fired.
Could you help me to fix that problem?
Feel free to contact my by e-mail.
Thanks
Best regards,
Marcos Lommez
Wow, I was amazed to the extend of work you put in this assembly. Thank you very much for your efforts. So far, it works fantastic. Big thanks.
loving this thing man! THanks! BUilding a timer tool that helps me track multitasking and also add notes to keep track of where i am with all. Lemme know if you’re interested i’ll send it to you - Rich
Anyone could help me to fix that problem in my previous post?
Thanks
Hi,
thank you for this awesome tuto and component !
I tried to add a webbrowser wpf component to the notification but it stays invisible (works when I click on it).
Do you have any idea to solve this ?
Regards
@Oz
I found why, this is cause by the AllowsTransparency attributes :
http://blogs.msdn.com/b/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx
Thanks
@Wietse Sas
Did you manage to come up with a solution for this?
Hi Sumi
Thank you for this great library. I just have one problem when my program closed, the icon is still in the tray bar. Only when my mouse is over it, then it vanishes. Here’s my code:
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
this.Hide();
tiNotify.Visibility = System.Windows.Visibility.Visible;
}
else tiNotify.Visibility = System.Windows.Visibility.Collapsed;
base.OnStateChanged(e);
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
//clean up notifyicon (would otherwise stay open until application finishes)
tiNotify.Dispose();
base.OnClosing(e);
}