Posts from December 2009

Dec
19
2009

Minimize To Tray with WPF



Posted in Programming and WPF

I’ve been working on porting LockCrypt to WPF from Java and was pretty shocked to find there was no no built-in support. It’s entirely possible, but you have to use WinForms. I based this on Delay‘s sample, feel free to use it however you wish.

namespace Lime49.WPF {
    /// <summary>
    /// Tray minimization utility, based on Delay's code - http://blogs.msdn.com/delay/.
    /// </summary>
    public static class TrayMinimizer {
        /// <summary>
        /// Enables "minimize to tray" behavior for the specified Window.
        /// </summary>
        /// <param name="window">Window to enable the behavior for.</param>
        public static void EnableMinimizeToTray(Window window) {
            if(MinimizeInstances.ContainsKey(window)) {
                Console.WriteLine(string.Format("Minimization already enabled for '{0}'", window.Title));
            } else {
                var instance = new MinimizeToTrayInstance(window);
                instance.Enable();
                MinimizeInstances.Add(window, instance);
            }
        }

Read more »