Winform:
One approach is to set the Cancel property to FormClosingEventArgs in the FormClosing event of your window and collapse to the tray instead. To minimize the tray, see this article:
Window tray minimizer
The Code Project contains more articles on this topic, but the one I worked with worked for me.
WPF:
I never had to do this in WPF, but still tried to find a solution. I found this:
Creating a Tray Icon for a WPF Application
You will find that the code works, but I recommend testing. The article discusses the opening of an application that is minimized in the tray.
You can also find this sample on MSDN useful:
Notification Icon Example
Jay riggs
source share