简体   繁体   中英

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. One more important thing - If we comment the line with Drawing.Icon the window doesn't close after running despite any tray options.

        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

It was very simple. I was trying to import WinForms for WPF. Here is everything explained about Notifyicon in WPF. Thanks to Andy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM