|
|
|
@ -641,47 +641,64 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Shows the window as a child of <paramref name="parent"/>.
|
|
|
|
/// Shows the window as a child of <paramref name="owner"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="parent">Window that will be a parent of the shown window.</param>
|
|
|
|
/// <param name="owner">Window that will be the owner of the shown window.</param>
|
|
|
|
/// <exception cref="InvalidOperationException">
|
|
|
|
/// The window has already been closed.
|
|
|
|
/// </exception>
|
|
|
|
public void Show(Window parent) |
|
|
|
public void Show(Window owner) |
|
|
|
{ |
|
|
|
if (parent is null) |
|
|
|
if (owner is null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(parent), "Showing a child window requires valid parent."); |
|
|
|
throw new ArgumentNullException(nameof(owner), "Showing a child window requires valid parent."); |
|
|
|
} |
|
|
|
|
|
|
|
ShowCore(parent); |
|
|
|
ShowCore(owner); |
|
|
|
} |
|
|
|
|
|
|
|
private void ShowCore(Window? parent) |
|
|
|
private void EnsureStateBeforeShow() |
|
|
|
{ |
|
|
|
if (PlatformImpl == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot re-show a closed window."); |
|
|
|
} |
|
|
|
|
|
|
|
if (_shown) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("The window is already being shown."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void EnsureParentStateBeforeShow(Window owner) |
|
|
|
{ |
|
|
|
if (owner.PlatformImpl == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show a window with a closed owner."); |
|
|
|
} |
|
|
|
|
|
|
|
if (owner == this) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("A Window cannot be its own owner."); |
|
|
|
} |
|
|
|
|
|
|
|
if (!owner.IsVisible) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show window with non-visible owner."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void ShowCore(Window? owner) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
IgnoreVisibilityChange = true; |
|
|
|
|
|
|
|
if (PlatformImpl == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot re-show a closed window."); |
|
|
|
} |
|
|
|
|
|
|
|
if (parent != null) |
|
|
|
EnsureStateBeforeShow(); |
|
|
|
|
|
|
|
if (owner != null) |
|
|
|
{ |
|
|
|
if (parent.PlatformImpl == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show a window with a closed parent."); |
|
|
|
} |
|
|
|
else if (parent == this) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("A Window cannot be its own parent."); |
|
|
|
} |
|
|
|
else if (!parent.IsVisible) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show window with non-visible parent."); |
|
|
|
} |
|
|
|
EnsureParentStateBeforeShow(owner); |
|
|
|
} |
|
|
|
|
|
|
|
if (_shown) |
|
|
|
@ -707,15 +724,15 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
LayoutManager.ExecuteInitialLayoutPass(); |
|
|
|
|
|
|
|
if (PlatformImpl != null && parent?.PlatformImpl is not null) |
|
|
|
if (PlatformImpl != null && owner?.PlatformImpl is not null) |
|
|
|
{ |
|
|
|
PlatformImpl.SetParent(parent.PlatformImpl); |
|
|
|
PlatformImpl.SetParent(owner.PlatformImpl); |
|
|
|
} |
|
|
|
|
|
|
|
Owner = parent; |
|
|
|
parent?.AddChild(this, false); |
|
|
|
Owner = owner; |
|
|
|
owner?.AddChild(this, false); |
|
|
|
|
|
|
|
SetWindowStartupLocation(parent?.PlatformImpl); |
|
|
|
SetWindowStartupLocation(owner?.PlatformImpl); |
|
|
|
|
|
|
|
PlatformImpl?.Show(ShowActivated, false); |
|
|
|
Renderer?.Start(); |
|
|
|
@ -758,26 +775,14 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
IgnoreVisibilityChange = true; |
|
|
|
|
|
|
|
EnsureStateBeforeShow(); |
|
|
|
|
|
|
|
if (owner == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(owner)); |
|
|
|
} |
|
|
|
else if (owner.PlatformImpl == null) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show a window with a closed owner."); |
|
|
|
} |
|
|
|
else if (owner == this) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("A Window cannot be its own owner."); |
|
|
|
} |
|
|
|
else if (IsVisible) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("The window is already being shown."); |
|
|
|
} |
|
|
|
else if (!owner.IsVisible) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Cannot show window with non-visible parent."); |
|
|
|
} |
|
|
|
|
|
|
|
EnsureParentStateBeforeShow(owner); |
|
|
|
|
|
|
|
RaiseEvent(new RoutedEventArgs(WindowOpenedEvent)); |
|
|
|
|
|
|
|
@ -800,7 +805,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
var result = new TaskCompletionSource<TResult>(); |
|
|
|
|
|
|
|
PlatformImpl?.SetParent(owner.PlatformImpl); |
|
|
|
PlatformImpl?.SetParent(owner.PlatformImpl!); |
|
|
|
Owner = owner; |
|
|
|
owner.AddChild(this, true); |
|
|
|
|
|
|
|
|