168

I am a total WPF newbie and wonder if anyone could give me some pointers how to write an application that starts minimized to tray. The idea is that it periodically fetches an RSS Feed and creates a Toaster-Popup when there are new feeds.

The Application should still have a Main Window (essentially just a list containing all feed entries), but that should be hidden by default.

I have started reading about XAML and WPF and I know that the StartupUri in the App.xaml has to point to my main window, but I have no idea what the proper way is to do the SysTray icon and hide the main window (this also means that when the user minimizes the window, it should minimize to tray, not to taskbar).

Any hints?

0

4 Answers 4

130

There's no NotifyIcon for WPF.

A colleague of mine used this freely available library to good effect:

Sign up to request clarification or add additional context in comments.

4 Comments

Drew, the link appears to have gone dead here. Do you have an alternative link for this library? I did a quick search, but couldn't determine if the results were for the same project.
@BradLarson, the site seems to be down; but anyway the project is available as Nuget package (see Dale's answer)
The large number of votes notwithstanding, this answer does not constitute a useful, legitimate Stack Overflow answer. It is effectively a link-only answer, contrary to Stack Overflow standards. Please improve this answer by providing the specific, material information in the answer itself. This will ensure the information is available regardless of the status of the external site.
And the picture also has no source attribution (was taken from the website), which also violates the guidelines.
55

I recently had this same problem. Unfortunately, NotifyIcon is only a Windows.Forms control at the moment, if you want to use it you are going to have to include that part of the framework. I guess that depends how much of a WPF purist you are.

If you want a quick and easy way of getting started check out this WPF NotifyIcon control on the Code Project which does not rely on the WinForms NotifyIcon at all. A more recent version seems to be available on the author's website and as a NuGet package. This seems like the best and cleanest way to me so far.

  • Rich ToolTips rather than text
  • WPF context menus and popups
  • Command support and routed events
  • Flexible data binding
  • Rich balloon messages rather than the default messages provides by the OS

Check it out. It comes with an amazing sample app too, very easy to use, and you can have great looking Windows Live Messenger style WPF popups, tooltips, and context menus. Perfect for displaying an RSS feed, I am using it for a similar purpose.

Comments

1

Simplest way that work, use the NotifyIcon from System.Windows.Forms.

Comments

1

Apparently there is no pure WPF bindings by Microsoft, but as mentioned before you can use one of third-party implementations.
Alternatively, you can do it by yourself from the scratch:

It all boils down to WinAPI calls:
https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyicona?redirectedfrom=MSDN
Those are C# bindings for those WinAPI functions:
https://www.pinvoke.net/default.aspx/shell32/Shell_NotifyIcon.html?diff=y

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.