如何在WPF中使用Windows元素(Notifyicon) [英] how to use the windows elements in wpf (notifyicon)

查看:65
本文介绍了如何在WPF中使用Windows元素(Notifyicon)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是wpf世界的新手.我想使用notifyicon,但我知道wpf不会显示notifyicon,因此我将命名空间用作"System.windows.Forms"

因此,它显示了如下错误

Hi,
I am new to the wpf world. I want to use the notifyicon but I know that wpf is not presenting the notifyicon, so that I am using the namespace as "System.windows.Forms"

Due to this it was showing the error as below

Error    10    ''Application'' is an ambiguous reference between ''System.Windows.Application'' and ''System.Windows.Forms.Application''    E:\All projects\oct\Gmailchecker\Gmailchecker\MainWindow.xaml.cs    248    13    Gmailchecker



我正在尝试这样:



I am trying like this:

 NotifyIcon notifyIcon = new NotifyIcon();     

this.notifyIcon.BalloonTipText = "hello";
this.notifyIcon.Text = "Gmail Alerts"; 
this.notifyIcon.Icon = new System.Drawing.Icon("NotifyIcon.ico"); 
this.notifyIcon.Visible = true;
this.notifyIcon.ShowBalloonTip(1000); /



请尝试帮助我避免此错误.
如何托管此类元素?
谢谢您的关注.



Please try to help me to avoid this error.
How to host this type of element?
Thank you for your attention.

推荐答案

您需要在代码中出现应用程序的任何地方使用完整的命名空间声明,因为System.WindowsSystem.Windows.Forms这两个命名空间都需要,具有称为Application的类,并且编译器无法确定要使用的类.在WPF应用程序中,我建议正确的名称空间为System.Windows

希望这对您有帮助
You need to use the full namespace declaration wherever Application occurs in your code, as both namespaces, System.Windows and System.Windows.Forms, have classes called Application, and the compiler cannot determine which one you want to use. In a WPF Application I would suggest that the correct namespace would be System.Windows

Hope this helps


作为替代,您可以创建一个使用别名指令":
As an alternative, you can create a "using alias directive":
using Forms = System.Windows.Forms


然后使用别名限定NotifyIcon引用:


and then qualify the NotifyIcon references with the alias:

Forms.NotifyIcon notifyIcon = new Forms.NotifyIcon();


我建​​议您使用此类而不是添加Winforms依赖项:

http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx [ ^ ]
Instead of adding a Winforms dependency, I''d recommend that you use this class:

http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx[^]


这篇关于如何在WPF中使用Windows元素(Notifyicon)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆