diff --git a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs index f61f29e2..761565c1 100644 --- a/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs +++ b/source/Components/Xceed.Wpf.AvalonDock/Controls/LayoutFloatingWindowControl.cs @@ -15,6 +15,7 @@ This program is provided to you under the terms of the Microsoft Public ***********************************************************************************/ using System; +using System.ComponentModel; using System.Linq; using System.Windows; using System.Runtime.InteropServices; @@ -58,6 +59,7 @@ protected LayoutFloatingWindowControl( ILayoutElement model ) { this.Loaded += new RoutedEventHandler( OnLoaded ); this.Unloaded += new RoutedEventHandler( OnUnloaded ); + Closing += OnClosing; _model = model; } @@ -453,6 +455,19 @@ private void OnUnloaded( object sender, RoutedEventArgs e ) } } + private void OnClosing(object sender, CancelEventArgs e) + { + Closing -= OnClosing; + + // If this window was Closed not from InternalClose method, + // mark it as closing to avoid "InvalidOperationException: : Cannot set Visibility to Visible or call Show, ShowDialog, + // Close, or WindowInteropHelper.EnsureHandle while a Window is closing". + if (!_isClosing) + { + _isClosing = true; + } + } + private void OnActivated( object sender, EventArgs e ) { this.Activated -= new EventHandler( OnActivated );