WPF NotifyIcon
Version 1.0.8 released April 2nd 2016.
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.
Browse/fork/clone on GitHub (includes sample application)
Download library via NuGet
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>
Hi,
I have a problem with my MVVM based WPF application.
Everything works well except calling the ShowBalloonTip function.
I have found this article:
http://stackoverflow.com/questions/12501348/how-to-implement-notifyicon-in-mvvm-project
…but I don’t want to configure the TaskbarIcon in the viewmodel code.
Could you help me, or it is not possible?
Thanks a lot!
Have a look in the samples – they should show you alternatives to configuring the NotifyIcon.
Is there a way to have a custom balloon use BalloonFlags.RespectQuietTime?
Hi Caroline
I’m not sure I’d implement this. I’ll think about it.
Thanks,
Philipp
Hi
i got an error when i start my program with this notifyicon via remote Connection (terminal Server).
I use Version 1.0.4.0. Is there a bugfix or is it fixed in a newer Version?
Thank you in advance
Michael
First of all thanks for lib, quite cool!
But i have a problem at Windows 8.1 on changing icon, idea of program is when you click on tray icon, it do something and changing icon from green to red, then red to green… etc.
changing like that:
MainWindow w = new MainWindow();
w.Tray1.Icon = new Icon(@”C:\red_light.ico”);
it don’t change icon, its just create new icon in tray list near, and if you click 10 times on my icon, it’ll be 10 icons in list with different colors…
what im have to do ? please email me if you can
This is an awesome effort that has helped me in my project and also learning WPF application coding. You have an excellent coding style and also great documentation. I have a unique requirement where I need to do multiple balloon popups and I am not able to time the interval between balloon popups. For example, I have 15 or so events that I need to balloon a popup and while I am enumerating the events and doing the popups, they all come out one after the other and only the last one stays. Introducing any thread.sleep or dispatch timer does not help. Any advice is much appreciated.
Awesome Control.
It would be great if you could add a flag to optionally remove the check for double-click as this adds a noticeable delay to the single-click event. In this case, double-click would not work of course, but I feel this is of less importance.
Rob,
This is a feature request I’ll be implementing with the upcoming version.
Thanks, Philipp
Hi,
Is there another way to create the xaml declaration xmlns:tb=”http://www.hardcodet.net/taskbar”?
Can’t this be contained with-in the project?
I have been burned before by web addresses just vanishing from the web.
Sorry if this is a “Basic” question, but I have been at C# WPF development for only a couple of months. I still have some holes in .net development to fill in.
Thanks
Jeff,
That URI is just an identifier – it doesn’t have anything to do with the website being existent. So even if hardcodet.net went down, you wouldn’t have to worry đ
Hi, please Help me
This not work in a Timer Elapsed method
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
FancyBalloon balloon = new FancyBalloon();
balloon.BalloonText = “blalblalbla”;
//show balloon and close it after 4 seconds
MyNotifyIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, 10000);
}
and the same code works fine in
private void button3_Click(object sender, RoutedEventArgs e)
{
FancyBalloon balloon = new FancyBalloon();
balloon.BalloonText = “blablalba”;
//show balloon and close it after 4 seconds
MyNotifyIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, 10000);
}
please help to solve this problem, it is very important to me ..
Are you on a background thread there?
No, it’s all in the main thread
I see that for taskbar popups, the default behavior when you mouse over the popup is to call taskbarIcon.ResetBalloonCloseTimer();
but once moused over, the popup never closes. am i missing something?
I have a menuitem in contextmenu for the trayicon.
menuitem just shows a MessageBox when clicked.
Problem is, MessageBox flashes and disappears very quickly.
Why is this?
Here is the basic code.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ScreenGrabberV3.TrayIcon
{
public class CustomContextMenu
{
public ContextMenu MyContextMenu { get; set; }
private MenuItem menuItem1 = new MenuItem();
private MenuItem menuItem2 = new MenuItem();
private MenuItem menuItem3 = new MenuItem();
private MenuItem menuItem4 = new MenuItem();
public CustomContextMenu()
{
MyContextMenu = new ContextMenu();
menuItem1.Header = BuildItemContent(“Exit”, new BitmapImage(new Uri(“pack://application:,,,/Resources/surveillance.png”)));
menuItem2.Header = BuildItemContent(“Show UI”, new BitmapImage(new Uri(“pack://application:,,,/Resources/surveillance.png”)));
menuItem1.Click += menuItem1_Click;
menuItem2.Click += menuItem2_Click;
MyContextMenu.Items.Add(menuItem1);
MyContextMenu.Items.Add(menuItem2);
}
private StackPanel BuildItemContent(string text, ImageSource image)
{
StackPanel stackPanel = new StackPanel {Orientation = Orientation.Horizontal};
Image imageObj = new Image {Source = image, Margin = new Thickness(0,0,10,0)};
Label labelObj = new Label {Content = text};
stackPanel.Children.Add(imageObj);
stackPanel.Children.Add(labelObj);
return stackPanel;
}
static void menuItem1_Click(object sender, System.Windows.RoutedEventArgs e)
{
e.Handled = true;
MessageBox.Show(“click”, “test” , MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
//messagebox flashes and disappears
}
void menuItem2_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
MessageBox.Show(“hello”);
//messagebox flashes and disappears
}
}
}
What does this mean?
I keep seeing this even though i have a contextmenu appearing when clicked.
Unhandled NotifyIcon message ID: 123
any cahnce of a version in nuget with a strong name?
Right now is there a better/recommended way to do this? Essentially what I’m doing is making the CustomBallon a modal dialog for the TrayPopup (Windowless).
private void UserControl_Loaded(object sender, RoutedEventArgs e) {
// make TrayPopup stay open and focus on THIS
TaskbarIcon.GetParentTaskbarIcon(this).TrayPopupResolved.StaysOpen = true;
WinApi.ActivatePopup(Parent);
}
private void OnBalloonClosing(object sender, RoutedEventArgs e) {
// allow TrayPopup to close and send focus back to it
Popup TrayPopupResolved = TaskbarIcon.GetParentTaskbarIcon(this).TrayPopupResolved;
TrayPopupResolved.StaysOpen = false;
WinApi.ActivatePopup(TrayPopupResolved);
}
responding to myself
The only problem I have with this is if you click outside the CustomBalloon the TextBoxes become unfocused again. If you activate the NotifyIcon by, say, left clicking on it then focus will come back to the CustomBalloon. I can’t find an event to listen for that is able to call ActivatePopup([CustomBalloon]) when you click back inside the CustomBalloon.
Is there a way to use DynamicResource to change the language of NotifyIcon MenuItems? It doesn’t work as expected.
Hi,
great work!
Just one thing: DynamicResource doesn’t work at runtime, so I can’t properly support internationalization because I need to restart the application every time I change the language to update MenuItems’ headers.
Is there a workaround for this issue?
Thanks.
Thanks so much for this project. It worked wonderfully for me. Even though I only needed a very minimal amount of functionality, the features I saw in the demo opened up a lot of possibilities for my app that I had previously not considered.
Well done!
Do you have any plans for hosting this at GitHub? That would be great for everything from issue tracking to the possibility of pull requests.
Maybe this is a trivial question but I’m using MVVM and the event which triggers the balloons is in the ViewModel so what is the best way to make this work? Should I declare the Notifyicon in the view model and if so how do I connect it with its context menu in the view, or if I leave it in the view, how do I call the ShowBalloon method in the view? I believe if I declare an instance in both the view and view model I’ll end up with 2 task tray items.
Thanks for the cool library.
Hi,
Your library is great and very helpful, thanks!
But it would be much better if you could host it on GitHub, because currently there is no easy way to see what has changed between one version and the next. I had to make a few changes to fix bugs or adapt it to my needs, but if I get the latest update from you, I have to reintegrate my changes manually, which is a pain… If it was on GitHub I could just fork the repo, make my changes (and possibly make a pull request for you to integrate them), and pull from your repo to merge your latest changes automatically.
I am having issue where if task bar icon is created pro grammatically or by using resource then clicking of tray icon doesn’t show context menu on top of icon. I see same issue with sample app (windowless sample)
@Rajeev
So I found out that this problem arise when you change screen resolution > make text or other items larger and smaller and then increase size from default to medium. However, this problem doesn’t occur when u create taskbar icon using window xaml
Great control! Been using it for a couple years in several projects. I’m having a problem where once the context menu has been activated on the tray icon, the context menu will not display at any other location when invoked by other controls. It continues to display in the location it did when it was invoked by the tray icon. Is this an issue with wpfNotifyIcon?
I like the helpful information you provide in your
articles. I’ll bookmark your weblog and check again here regularly.
I am quite sure I’ll learn many new stuff right here!
Best of luck for the next!
Hi,
This library is great. Good job.
I have one question. How can I show custom balloon without closing actual balloon?
I use tryicon for showing new message in my chat application and I want show all new message as custom balloon.
Can you help me?
Having trouble with the IconSource. I can do this ok…
but I can’t do this…
I get an exception…
An exception of type ‘System.ArgumentException’ occurred in Hardcodet.Wpf.TaskbarNotification.dll but was not handled in user code
Additional information: The supplied image source ‘pack://application:,,,/KcTrayApp;component/Images/Kc_16x16.png’ could not be resolved.
My image is set as content & copy always. Visual Studio 2013 update 4, used nuget to obtain notifyicon.
cheers.
Having trouble with the IconSource. I can do this okâŠ
<Button>
<Image Source="Images/Kc_16x16.png" />
</Button>
but I canât do thisâŠ
<tb:TaskbarIcon
IconSource="Images/Kc_16x16.png"
ToolTipText="blah blah" />
I get an exceptionâŠ
An exception of type âSystem.ArgumentExceptionâ occurred in Hardcodet.Wpf.TaskbarNotification.dll but was not handled in user code
Additional information: The supplied image source âpack://application:,,,/KcTrayApp;component/Images/Kc_16x16.pngâ could not be resolved.
My image is set as content & copy always. Visual Studio 2013 update 4, used nuget to obtain notifyicon.
Sorry about the previous post – hopefully the xaml is escaped properly now.
cheers.
I used an online tool to quicky escape the xaml. Pretty handy…
http://www.accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php
So, I’ve found out how to get it to work. The image must be an ico, as a png will not work and the settings must be resource + do not copy. Using content + copy always does not work.
Hi,
great Library!!!
I am facing an issue related to display of Balloon as it appears overriding taskbar… In your original sample it is shown correctly above taskbar but I seem unable to replicate it. What could I been missing?
Do you have an example where you bind the IconSource property to a viewmodel using a .ico file? I am struggling to set it up properly. Thanks for the great toolbar icon.
I am facing issue while integrating notifyicon with windows service. Always i used to get the error unable to find appbar that matches the given criteria.
I have create on exe when you double click on exe it will show notification. By double clicking this works.
But when i make this exe to run as scheduler again i am getting error unable to find appbar that matches the given criteria.
Please Let me know where i have done the mistake ?
Solved Issue i have posted this sanghimz.blogspot.com
Reason i was getting error because library was unable to find the Window in Windows 7 due to change in application session and windows service session
I create an icon that when running on Citrix has visibility set to collapsed. If my citrix client gets disconnected then reconnects to the same station, I get the icon appearing. Any idea why or suggested fixes? Upon normal operation, no icon appears from citrix(which is what i want)
@Krishna
And what was the fix?
I have an issue with Windows 8.x. When notify icons are grouped context menu is showed at wrong coordinates.
Is this a known issue and any plans to fix it?
@Mino
Hi, that’s exactly what I’m creating: some sort of chat application. And looks like this lib doesn’t support more than 1 balloon.
Have you managed to work it out?
Hi,
I must appreciate that you have done a great job, Thank you so much.
Well this time I am trying like : I am having an application with 2 different notification icons..
but thing is happening like they are having common behavior for ex. if I am trying to hide or show or notification only for one icon it automatically applies to both, don’t know whats going wrong ? I am not sure but is it because of identifier needs to be given or because of they are from one and single application..?
Thanks & Regards,
Nilesh
i have an issue in showstandaredballon ballon not displayed.
private void btnShowStandardBalloon_Click(object sender, RoutedEventArgs e)
{
string title = “WPF NotifyIcon”;
string text = “This is a standard balloon”;
MyNotifyIcon.ShowBalloonTip(title, text, MyNotifyIcon.Icon);
}
should i declare more any more…???????
Hi guys,
Iâm experiencing some trouble with the tooltip. Sometimes (always fun with inconsequence, right?) when a tooltip is displayed it stays on the screen and wonât disappear until the computer is rebooted. I understand that this is pretty much the worst kind of error description there is, but does anyone else experiencing this or have any tip how to prevent it?
Thanks for a great library, cheers!
@Mino
Have you figured it out? I have same question
Some events not firing – like MouseEnter, MouseLeave, etc. But very nice and straight forward…
Is it possible to get a popup to appear on a Context Menu item?
Hello, how can I programmatically close the popup?
I have an issue, when I open a window from the popup, the popup doesn’t lose focus and close,
and stays open.
So I have to click twice in the new window – First time, for the popup to close, and second to make the operation I wanted on the new window.
Thanks!
please how can i use this in my 3.5 .net project