0

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

Sweazy
  • 1
  • 3
  • 2
    If you are using WPF, then why are you trying to import WinForms? Take a look at [this question](https://stackoverflow.com/questions/1472633/wpf-application-that-only-has-a-tray-icon). – Andy Aug 23 '21 at 00:21
  • Thank you so much, Andy, you just made my evening. Thanks to you I will go to bed in a good mood. – Sweazy Aug 23 '21 at 00:43

1 Answers1

0

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

Sweazy
  • 1
  • 3