question

RomanReiter-0099 avatar image
0 Votes"
RomanReiter-0099 asked PeterSandersNL commented

Minimize a WPF application to System Tray in C#

Hi,

First of all, I want to create a WPF that can be minimized in the Windows taskbar (next to the clock).


Second, I want to change the WPF's Incon icon when the wpf is minimized.


Thirdly, when the WPF is minimized, it should display action messages (such as Outlook when you receive an email or display a message to the user when a connection is lost).

BW Roman

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RodAtWork avatar image
0 Votes"
RodAtWork answered RodAtWork edited

If you want it in the system tray I think what you'll have to do is make it a Windows service. I've only written 1 Windows Service and that was years ago, but I believe that's what you'll have to do.

If I'm correct about writing a Windows service, then what I would suggest you do is create a new Visual Studio solution and add two projects to it. One would be a DLL which would run as a Windows service. The second project would be a WPF project that will be your UI the user interacts with. Then you'll have to use some messaging system to communicate between the two.

For the action messages that would mimic what Outlook does, I've used some WPF toast messages to accomplish that. If you Bing/Google "WPF toast popup" you'll get lots of results.

I hope this helps.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

lextm avatar image
1 Vote"
lextm answered AmyPeng1-MSFT commented

The true difficulty was that WPF on .NET Framework never has a tray icon control. But if you use the WinForms tray icon control, you just need a few lines of code to implement the feature,

https://possemeeg.wordpress.com/2007/09/06/minimize-to-tray-icon-in-wpf/

You might use third party tray icon for WPF as well.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Great Tip! I usually just design an app and other people build my designed, but with this tip (lextm tip) I managed to build the extra functionality in the app in 5 minutes!

0 Votes 0 ·