[英]WPF C# Tray Icon Implementation Issue
I've faced the issue while trying to implement a tray icon.我在尝试实现托盘图标时遇到了这个问题。 App was instantly closing every time I launched it.
每次我启动它时,应用程序都会立即关闭。 So first thing first I decided to create a new project to try it there, just in case if I messed something up in my app.
所以首先我决定创建一个新项目在那里尝试它,以防万一我在我的应用程序中搞砸了。 But it proceeded to close.
但它继续关闭。 In this new project, I just removed StartupUri and added this piece of code.
在这个新项目中,我只是删除了 StartupUri 并添加了这段代码。 One more important thing - If we comment the line with Drawing.Icon the window doesn't close after running despite any tray options.
一件更重要的事情 - 如果我们用 Drawing.Icon 注释该行,则 window 在运行后不会关闭,尽管有任何托盘选项。
protected override void OnStartup(StartupEventArgs e)
{
MainWindow = new MainWindow();
MainWindow.Show();
Forms.NotifyIcon _notifyIcon = new Forms.NotifyIcon();
_notifyIcon.Icon = new System.Drawing.Icon("icon.ico");
_notifyIcon.Visible = true;
base.OnStartup(e);
}
I would be extremely grateful if you could help me to figure it out如果你能帮我弄清楚,我将不胜感激
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.