Minimizing Application to system tray using WPF ( Not using NotifyIcon )

て烟熏妆下的殇ゞ 提交于 2019-11-28 05:56:25
Marksl

If you'll reconsider your reluctance to using an external component, I recommend WPF NotifyIcon. I've used it. It's straightforward and works well.

It does not just rely on the corresponding WinForms component, but is a purely independent control which leverages several features of the WPF framework in order to display rich tooltips, popups, context menus, and balloon messages.

I just came across this post today.

For reference, I also solved this some time back. It works very well and the only time I have had a bit of an issue is occasionally on some multi-display set ups.

This was before GITs and NuGets were the in-thing, I will place it in a GIT repo if there is interest.

CodeProject Article Here

Here is a thread , which helped me a lot .

https://stackoverflow.com/a/12428063/10305444

public partial class Window : System.Windows.Window{


public Window()
{
    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 == WindowState.Minimized)
        this.Hide();

    base.OnStateChanged(e);
}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!