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

2
  • 2
    If you are using WPF, then why are you trying to import WinForms? Take a look at this question. Commented Aug 23, 2021 at 0:21
  • Thank you so much, Andy, you just made my evening. Thanks to you I will go to bed in a good mood. Commented Aug 23, 2021 at 0:43

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.