C# 使用 WPF 将应用程序最小化到系统托盘(不使用 NotifyIcon)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14700606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Minimizing Application to system tray using WPF ( Not using NotifyIcon )
提问by rockstar
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 .
我完成了我的应用程序,现在我想为它合并“最小化到系统托盘功能”。我读了一篇好文章 将应用程序最小化到系统托盘。我意识到这些利用了 Windows.Form 类。
Unfortunately I have used Windows Presentation Foundation WPF referenceto 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 ContribI have not used it as yet .
不幸的是,我使用 Windows Presentation Foundation WPF 参考来制作我的应用程序 UI。现在我看到 WPF 不支持 NotifyIcon。我看到 CodePlex 上有一个开源库可以模拟 NotifyIcon 属性WPF Contrib我还没有使用它。
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 .
a) 我不想只为一个组件合并一个 3'rd 方库。
b) Can I do the minimizing feature without NotifyIcon on WPF? If yes then how can someone give me leads please ?
b) 我可以在 WPF 上没有 NotifyIcon 的情况下执行最小化功能吗?如果是的话,那么有人怎么能给我线索呢?
Or maybe I should revert my UI back to using Windows Forms ?
或者我应该将我的 UI 恢复为使用 Windows 窗体?
采纳答案by 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.
如果您重新考虑您不愿意使用外部组件,我推荐 WPF NotifyIcon。我用过。它很简单,而且效果很好。
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.
它不仅依赖于相应的 WinForms 组件,而且还是一个纯粹的独立控件,它利用了 WPF 框架的多个功能来显示丰富的工具提示、弹出窗口、上下文菜单和气球消息。
回答by Murray Foxcroft
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.
这是在 GIT 和 NuGet 出现之前,如果有兴趣,我会将它放在 GIT 存储库中。
回答by Maifee Ul Asad
Here is a thread , which helped me a lot .
这是一个线程,对我帮助很大。
https://stackoverflow.com/a/12428063/10305444
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);
}}