I'm making a new WPF application and I need to be able to minimize the application and have nice and snug in the system tray, right beside the clock (or in that general area).
This has to work on Windows XP, Vista and 7. I don't have to support older versions of Windows.
What's the simplest way to achieve this if I'm using .NET 4?
Example in MSDN forum
Here's a quick example to show how to minimize to the notification area. You need to add references to the System.Window.Forms
and System.Drawing
assemblies.
public partial class Window1 : System.Windows.Window { public Window1() { InitializeComponent(); System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Icon = new System.Drawing.Icon("Main.ico"); ni.Visible = true; ni.DoubleClick += delegate(object sender, EventArgs args) { this.Show(); this.WindowState = WindowState.Normal; }; } protected override void OnStateChanged(EventArgs e) { if (WindowState == System.Windows.WindowState.Minimized) this.Hide(); base.OnStateChanged(e); } }
I've had success using this free notify-icon implementation in WPF.
http://www.hardcodet.net/projects/wpf-notifyicon
It's pretty simple to setup and the source code is provided. It doesn't rely on Windows Forms, so it's 'pure' WPF and very customizable.
You can find a tutorial on how to use it on CodeProject.
And here is the Nuget Package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With