Skip to content

Commit

Permalink
Merge pull request #2696 from cwensley/curtis/wpf-dialog-visible
Browse files Browse the repository at this point in the history
Wpf: Setting Dialog.Visible=false after shown should not crash
  • Loading branch information
cwensley authored Oct 24, 2024
2 parents 66d5838 + 0a878f5 commit 7870805
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Eto.Wpf/Forms/DialogHandler.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override AutomationPeer OnCreateAutomationPeer()
return new EtoWindowAutomationPeer(this);
}
}

public class DialogHandler : WpfWindow<sw.Window, Dialog, Dialog.ICallback>, Dialog.IHandler
{
Button defaultButton;
Expand All @@ -64,7 +64,7 @@ public DialogHandler(sw.Window window)
protected override void Initialize()
{
base.Initialize();

Resizable = false;
Minimizable = false;
Maximizable = false;
Expand All @@ -85,7 +85,7 @@ public void ShowModal()
ReloadButtons();

var owner = Widget.Owner;

if (LocationSet)
{
Control.WindowStartupLocation = sw.WindowStartupLocation.Manual;
Expand All @@ -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();
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Wpf/Forms/WpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 7870805

Please sign in to comment.