Can I use NotifyIcon in WPF? Can I use NotifyIcon in WPF? windows windows

Can I use NotifyIcon in WPF?


NotifyIcon is not implemented in WPF as it is in Forms, but you can still use the Windows Form NotifyIcon, it resides in the System.Windows.Forms namspace.

Take a look at these tutorials, they might cover your needs:

Simple solution, directly using NotifyIcon:http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html

More advanced solution, new library based on NotifyIcon with more features:http://www.codeproject.com/Articles/36468/WPF-NotifyIcon

More info about NotifyIcon can be found here:http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx


You can set your code for the NotifyIcon in App.xaml.cs

using System.Drawing;namespace DDD{    /// <summary>    /// Interaction logic for App.xaml    /// </summary>    public partial class App : Application    {        System.Windows.Forms.NotifyIcon nIcon = new System.Windows.Forms.NotifyIcon();        public App()        {            nIcon.Icon = new Icon(@"path to ico");            nIcon.Visible = true;            nIcon.ShowBalloonTip(5000, "Title", "Text",  System.Windows.Forms.ToolTipIcon.Info);            nIcon.Click += nIcon_Click;        }        void nIcon_Click(object sender, EventArgs e)        {            //events comes here            MainWindow.Visibility = Visibility.Visible;            MainWindow.WindowState = WindowState.Normal;        }    }}

And in your Mainwindow.xaml.cs:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)    {        e.Cancel = true;        this.Visibility = Visibility.Hidden;    }

Make sure that Window_Closing is binded to the closing event of the main window.

If you "close" your main window, the window visibility wil be set to hidden but your app will be still running.Simple click on the NotifyIcon in the notification area and there is your window back.


Yes, it is possible, and I used it with success in my personal project. There is an excelent control written by Philip Sumi http://www.hardcodet.net/projects/wpf-notifyicon. I used precisly that one and it works really great and looks nice (subjective).

image

Just note: pay attention licensing terms, check out if you can use it in your project.