From 6d39f5965b225fbbb833f76d2ebac73237864dbc Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 18 Sep 2012 16:54:59 +0200 Subject: [PATCH] [AvalonDock] Fix "InvalidOperationException: This Visual is not connected to a PresentationSource" when closing a view content by middle-clicking while holding the left mouse button. --- src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs b/src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs index 1259179fe0..501ac136bd 100644 --- a/src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs +++ b/src/Libraries/AvalonDock/AvalonDock/ManagedContent.cs @@ -337,7 +337,9 @@ namespace AvalonDock protected virtual void OnDragMouseLeave(object sender, MouseEventArgs e) { - if (!e.Handled && isMouseDown && e.LeftButton == MouseButtonState.Pressed && Manager != null) + // The MouseLeave event can occur if the managed content was closed while the user held the left mouse button pressed. + // In that case, this.IsLoaded will be false and we won't handle the event + if (!e.Handled && isMouseDown && e.LeftButton == MouseButtonState.Pressed && Manager != null && this.IsLoaded) { if (!IsMouseCaptured) {