From 0a878f5709195b12139a7835a63d935ecceb291a Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Thu, 24 Oct 2024 14:13:44 -0700 Subject: [PATCH] Wpf: Setting Dialog.Visible=false after shown should not crash --- src/Eto.Wpf/Forms/DialogHandler.cs | 15 +++++++++++---- src/Eto.Wpf/Forms/WpfWindow.cs | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/Eto.Wpf/Forms/DialogHandler.cs diff --git a/src/Eto.Wpf/Forms/DialogHandler.cs b/src/Eto.Wpf/Forms/DialogHandler.cs old mode 100644 new mode 100755 index c0ad10465..7dc2d1675 --- a/src/Eto.Wpf/Forms/DialogHandler.cs +++ b/src/Eto.Wpf/Forms/DialogHandler.cs @@ -37,7 +37,7 @@ protected override AutomationPeer OnCreateAutomationPeer() return new EtoWindowAutomationPeer(this); } } - + public class DialogHandler : WpfWindow, Dialog.IHandler { Button defaultButton; @@ -64,7 +64,7 @@ public DialogHandler(sw.Window window) protected override void Initialize() { base.Initialize(); - + Resizable = false; Minimizable = false; Maximizable = false; @@ -85,7 +85,7 @@ public void ShowModal() ReloadButtons(); var owner = Widget.Owner; - + if (LocationSet) { Control.WindowStartupLocation = sw.WindowStartupLocation.Manual; @@ -97,7 +97,7 @@ public void ShowModal() parentWindowBounds = owner.Bounds; Control.Loaded += HandleLoaded; } - + // if the owner doesn't have focus, windows changes the owner's z-order after the dialog closes. if (owner != null && !owner.HasFocus) owner.Focus(); @@ -120,6 +120,13 @@ public void ShowModal() ClearButtons(); } + public override void SetOwner(Window owner) + { + // Dialogs can not change owner after shown + if (!Widget.Loaded) + base.SetOwner(owner); + } + void Control_PreviewKeyDown(object sender, sw.Input.KeyEventArgs e) { if (e.Key == sw.Input.Key.Escape && AbortButton != null) diff --git a/src/Eto.Wpf/Forms/WpfWindow.cs b/src/Eto.Wpf/Forms/WpfWindow.cs index f7b4fc6c4..8cac8b32e 100755 --- a/src/Eto.Wpf/Forms/WpfWindow.cs +++ b/src/Eto.Wpf/Forms/WpfWindow.cs @@ -1075,7 +1075,7 @@ public void SetOwnerFor(sw.Window child) child.Owner = Control; } - public void SetOwner(Window owner) + public virtual void SetOwner(Window owner) { if (owner == null) {