Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wpf: Setting Dialog.Visible=false after shown should not crash #2696

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading