Browse Source

ensure correct parent is set when window owner changes (#14351)

Co-authored-by: Max Katz <maxkatz6@outlook.com>
pull/14157
Emmanuel Hansen 2 years ago
committed by GitHub
parent
commit
e6f0c8dbee
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 44
      src/Avalonia.Controls/Window.cs

44
src/Avalonia.Controls/Window.cs

@ -478,16 +478,11 @@ namespace Avalonia.Controls
child.CloseInternal();
}
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
Owner = null;
PlatformImpl?.Dispose();
_showingAsDialog = false;
Owner = null;
}
private bool ShouldCancelClose(WindowClosingEventArgs args)
@ -554,11 +549,6 @@ namespace Avalonia.Controls
StopRendering();
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
if (_children.Count > 0)
{
foreach (var child in _children.ToArray())
@ -567,10 +557,11 @@ namespace Avalonia.Controls
}
}
Owner = null;
PlatformImpl?.Hide();
IsVisible = false;
_shown = false;
Owner = null;
}
}
@ -689,13 +680,7 @@ namespace Avalonia.Controls
LayoutManager.ExecuteInitialLayoutPass();
if (PlatformImpl != null && owner?.PlatformImpl is not null)
{
PlatformImpl.SetParent(owner.PlatformImpl);
}
Owner = owner;
owner?.AddChild(this, false);
SetWindowStartupLocation(owner);
@ -770,9 +755,7 @@ namespace Avalonia.Controls
var result = new TaskCompletionSource<TResult>();
PlatformImpl?.SetParent(owner.PlatformImpl!);
Owner = owner;
owner.AddChild(this, true);
SetWindowStartupLocation(owner);
@ -974,11 +957,6 @@ namespace Avalonia.Controls
base.HandleClosed();
if (Owner is Window owner)
{
owner.RemoveChild(this);
}
Owner = null;
}
@ -1031,6 +1009,20 @@ namespace Avalonia.Controls
PlatformImpl?.SetSystemDecorations(typedNewValue);
}
if (change.Property == OwnerProperty)
{
var oldParent = change.OldValue as Window;
var newParent = change.NewValue as Window;
oldParent?.RemoveChild(this);
newParent?.AddChild(this, _showingAsDialog);
if (PlatformImpl is IWindowImpl impl)
{
impl.SetParent(_showingAsDialog ? newParent?.PlatformImpl! : (newParent?.PlatformImpl ?? null));
}
}
}
protected override AutomationPeer OnCreateAutomationPeer()

Loading…
Cancel
Save