Minimize a WPF application to System Tray in C#

Roman Reiter 1 Reputation point
2020-03-25T14:12:22.62+00:00

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 Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,372 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 3,481 Reputation points
    2020-05-25T01:48:09.967+00:00

    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 person found this answer helpful.

  2. Rod At Work 846 Reputation points
    2020-03-25T22:10:23.373+00:00

    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.

    0 comments No comments