WPF NotifyIcon

April 2nd, 2016

 

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.

image

Browse/fork/clone Git repository (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.

quickaccess

 

image

 

image

 

image

 

image

 

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>
  1. Spuriga
    February 17th, 2014 at 10:50 | #1

    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!

    • April 14th, 2014 at 19:49 | #2

      Have a look in the samples – they should show you alternatives to configuring the NotifyIcon.

  2. Caroline Stepnowski
    February 18th, 2014 at 01:53 | #3

    Is there a way to have a custom balloon use BalloonFlags.RespectQuietTime?

    • April 14th, 2014 at 19:48 | #4

      Hi Caroline

      I’m not sure I’d implement this. I’ll think about it.

      Thanks,
      Philipp

  3. MichaB
    February 28th, 2014 at 08:20 | #5

    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

  4. Hi i got the problem
    March 6th, 2014 at 16:34 | #6

    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

  5. Sriram
    March 13th, 2014 at 00:00 | #7

    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.

  6. Rob Moran
    March 19th, 2014 at 14:00 | #8

    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.

    • April 14th, 2014 at 19:46 | #9

      Rob,

      This is a feature request I’ll be implementing with the upcoming version.

      Thanks, Philipp

  7. Jeff
    April 2nd, 2014 at 20:11 | #10

    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

    • April 14th, 2014 at 19:46 | #11

      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 🙂

  8. Alexey
    April 14th, 2014 at 19:03 | #12

    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 ..

  9. Alexey
    April 14th, 2014 at 20:09 | #14

    No, it’s all in the main thread

  10. Julien
    April 28th, 2014 at 13:14 | #15

    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?

  11. Dojo
    April 30th, 2014 at 09:53 | #16

    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
    }
    }
    }

  12. Dojo
    April 30th, 2014 at 10:13 | #17

    What does this mean?
    I keep seeing this even though i have a contextmenu appearing when clicked.
    Unhandled NotifyIcon message ID: 123

  13. Jens Schumacher
    May 4th, 2014 at 23:33 | #18

    any cahnce of a version in nuget with a strong name?

  14. ltguide
    May 12th, 2014 at 08:15 | #19

    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);
    }

  15. ltguide
    May 14th, 2014 at 18:07 | #20

    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.

  16. July 25th, 2014 at 15:21 | #21

    Is there a way to use DynamicResource to change the language of NotifyIcon MenuItems? It doesn’t work as expected.

  17. July 25th, 2014 at 19:29 | #22

    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.

  18. Bruce
    August 27th, 2014 at 12:56 | #23

    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!

  19. John
    September 1st, 2014 at 20:53 | #24

    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.

  20. Newbie on the loose
    September 9th, 2014 at 05:26 | #25

    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.

  21. September 29th, 2014 at 09:27 | #26

    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.

  22. Rajeev
    October 1st, 2014 at 19:36 | #27

    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)

  23. Rajeev
    October 2nd, 2014 at 02:04 | #28

    @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

  24. October 11th, 2014 at 14:25 | #29

    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?

  25. November 2nd, 2014 at 01:13 | #30

    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!

  26. November 9th, 2014 at 15:55 | #31

    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?

  27. Kristian
    November 29th, 2014 at 07:14 | #32

    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.

  28. Kristian
    November 29th, 2014 at 07:30 | #33

    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.

  29. Kristian
    November 29th, 2014 at 07:32 | #34

    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

  30. Kristian
    November 29th, 2014 at 07:56 | #35

    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.

  31. Ricardo Figueiredo
    December 2nd, 2014 at 15:01 | #36

    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?

  32. ptaylor
    December 2nd, 2014 at 15:49 | #37

    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.

  33. Krishna
    January 9th, 2015 at 05:13 | #38

    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 ?

  34. Krishna
    January 9th, 2015 at 12:19 | #39

    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

  35. John
    January 16th, 2015 at 16:46 | #40

    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)

  36. Alexander
    January 21st, 2015 at 11:37 | #41

    @Krishna
    And what was the fix?

  37. Umut
    February 12th, 2015 at 09:35 | #42

    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?

  38. February 16th, 2015 at 12:15 | #43

    @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?

  39. Nilesh
    February 20th, 2015 at 13:38 | #44

    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

  40. pandiyan
    March 6th, 2015 at 09:00 | #45

    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…???????

  41. Robin Bengtsson
    March 17th, 2015 at 10:13 | #46

    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!

  42. Khoa
    June 3rd, 2015 at 02:52 | #47

    @Mino
    Have you figured it out? I have same question

  43. June 3rd, 2015 at 09:08 | #48

    Some events not firing – like MouseEnter, MouseLeave, etc. But very nice and straight forward…

  44. Will
    June 26th, 2015 at 20:30 | #49

    Is it possible to get a popup to appear on a Context Menu item?

  45. Rony
    July 8th, 2015 at 16:44 | #50

    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!

  46. abbaty48
    July 9th, 2015 at 13:32 | #51

    please how can i use this in my 3.5 .net project

Comment pages
1 3 4 5 6 452
  1. March 10th, 2014 at 10:13 | #1
  2. March 14th, 2014 at 13:57 | #2
  3. February 27th, 2015 at 15:06 | #3
  4. July 9th, 2015 at 02:50 | #4