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

大兔子大兔子 提交于 2019-11-27 00:56:07

问题


I am finished making my application and now I want to incorporate " minimizing into the system tray feature " for it . I read up a good article minimize app to system tray . I realized that these make use of the Windows.Form class .

Unfortunately I have used Windows Presentation Foundation WPF reference to make my applications UI . Now I see that the NotifyIcon is not supported in WPF. I see that there is an open source library on CodePlex that simulates the NotifyIcon properties WPF Contrib I have not used it as yet .

Now I am in a fix . Here are my questions :-

a) I don't want to incorporate a 3'rd party library just for one single component .

b) Can I do the minimizing feature without NotifyIcon on WPF? If yes then how can someone give me leads please ?

Or maybe I should revert my UI back to using Windows Forms ?


回答1:


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.




回答2:


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




回答3:


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);
}}


来源:https://stackoverflow.com/questions/14700606/minimizing-application-to-system-tray-using-wpf-not-using-notifyicon

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