picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.57k stars 325 forks source link

[WPF] Exception if trying to prevent closing of a window #1131

Open MartinRothschink opened 6 years ago

MartinRothschink commented 6 years ago

This is related to issue #1130. If main window is visible and OnClosing sets e.Cancel = true to prevent closing, an exception is thrown for this sequence:

Expected Behavior

No exception.

Actual Behavior

Exception after above sequence.

Code that Demonstrates the Problem

using Eto.Forms;
using Eto.Drawing;

namespace EtoTrayApp
{
   using System.ComponentModel;

   public partial class MainForm : Form
   {
      private TrayIndicator _tray;
      public MainForm()
      {
         Title = "My Eto Form";
         ClientSize = new Size(200, 200);
         _tray = new TrayIndicator
         {
            Image = Eto.Drawing.Icon.FromResource("EtoTrayApp.error.ico"),
            Menu = new ContextMenu
            {
               Items =
               {
                   new ButtonMenuItem {Text = "Quit", Command = new Command((s, e) => Application.Instance.Quit())}
               }
            }
         };

         ShowInTaskbar = false;
         _tray.Visible = true;
      }

      protected override void OnClosing(CancelEventArgs e)
      {
         base.OnClosing(e);
     e.Cancel = true;
      }
   }
}

Specifications

MartinRothschink commented 6 years ago

This exception does not happen on MAC and GTK. However the red X hides the window on a MAC (platform difference)..