C#trayicon使用wpf

我是C#编程的新手,虽然我已经在unity3D中用C#编写了几年。 我正在尝试制作一个WPF托盘图标,我在网上找到的所有资源告诉我使用

System.Windows.Forms 

但是。对于我来说,System.Windows中没有.Forms,我不知道为什么不这样做。 谁能帮我这个?

您需要添加对System.Window.Forms和System.Drawing程序集的引用,然后像这样使用它。 假设您尝试最小化Window to tray图标并在用户单击该图标时再次显示它:

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

您需要添加对System.Windows.Forms.dll的引用,然后使用NotifyIcon类。

http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx