Question

How can I send the window minimized to tray when on click close button? Also how to show icon in tray when application start?

Was it helpful?

Solution

There is nothing that comes embedded with WPF. From implementations that you can find on the net, there is an "easy" one, that uses WinForms:

http://msdn.microsoft.com/en-us/library/aa972170.aspx

But I like this one more (can be used for balloon tips too)

http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx

OTHER TIPS

WinForm:

One approach is to set the Cancel property of FormClosingEventArgs in the FormClosing event of your window and instead minimize to tray. For minimizing to tray, see this article:

Window Tray Minimizer

Code Project has more articles on the topic, but the one I linked worked for me.

WPF:

I've never had to do this in WPF but did poke around for a solution. I found this:

Creating a Tray Icon for a WPF Application

You'll find the code works but I recommend testing. The article addresses opening an application minimized to the tray.

You might also find this sample on MSDN useful:

Notification Icon Sample

In winforms you can overload WndProc and watch for the WM_CLOSE message.

    WM_CLOSE = 0x0010

    protected override void WndProc(ref Message m)
    {
      if(m.Msg == WM_CLOSE)
      {
        this.Hide();
        trayIcon.Show();
      }

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top