@ -201,6 +201,7 @@ namespace Avalonia.Controls
private bool _ showingAsDialog ;
private bool _ positionWasSet ;
private bool _ wasShownBefore ;
private IDisposable ? _ modalSubscription ;
/// <summary>
/// Initializes static members of the <see cref="Window"/> class.
@ -612,11 +613,12 @@ namespace Avalonia.Controls
}
}
Owner = null ;
PlatformImpl ? . Hide ( ) ;
IsVisible = false ;
_ shown = false ;
Owner = null ;
_ modalSubscription ? . Dispose ( ) ;
_ shown = false ;
}
}
@ -645,14 +647,7 @@ namespace Avalonia.Controls
}
else
{
if ( _ showingAsDialog )
{
Close ( false ) ;
}
else
{
Hide ( ) ;
}
Hide ( ) ;
}
}
}
@ -706,7 +701,7 @@ namespace Avalonia.Controls
using ( FreezeVisibilityChangeHandling ( ) )
{
EnsureStateBeforeShow ( ) ;
if ( modal & & owner = = null )
{
throw new ArgumentNullException ( nameof ( owner ) ) ;
@ -738,14 +733,14 @@ namespace Avalonia.Controls
var initialSize = new Size (
double . IsNaN ( Width ) ? ClientSize . Width : Width ,
double . IsNaN ( Height ) ? ClientSize . Height : Height ) ;
initialSize = new Size (
MathUtilities . Clamp ( initialSize . Width , MinWidth , MaxWidth ) ,
MathUtilities . Clamp ( initialSize . Height , MinHeight , MaxHeight ) ) ;
var clientSizeChanged = initialSize ! = ClientSize ;
ClientSize = initialSize ; // ClientSize is required for Measure and Arrange
// this will call ArrangeSetBounds
LayoutManager . ExecuteInitialLayoutPass ( ) ;
@ -762,21 +757,21 @@ namespace Avalonia.Controls
clientSizeChanged | = initialSize ! = ClientSize ;
ClientSize = initialSize ;
}
Owner = owner ;
SetWindowStartupLocation ( owner ) ;
DesktopScalingOverride = null ;
if ( clientSizeChanged | | ClientSize ! = PlatformImpl ? . ClientSize )
{
// Previously it was called before ExecuteInitialLayoutPass
PlatformImpl ? . Resize ( ClientSize , WindowResizeReason . Layout ) ;
// we do not want PlatformImpl?.Resize to trigger HandleResized yet because it will set Width and Height.
// So perform some important actions from HandleResized
Renderer . Resized ( ClientSize ) ;
OnResized ( new WindowResizedEventArgs ( ClientSize , WindowResizeReason . Layout ) ) ;
@ -788,8 +783,8 @@ namespace Avalonia.Controls
FrameSize = PlatformImpl ? . FrameSize ;
_ canHandleResized = true ;
_ canHandleResized = true ;
StartRendering ( ) ;
PlatformImpl ? . Show ( ShowActivated , modal ) ;
@ -798,22 +793,32 @@ namespace Avalonia.Controls
{
var tcs = new TaskCompletionSource < TResult > ( ) ;
Observable . FromEventPattern (
var disposables = new CompositeDisposable (
[
Observable . FromEventPattern (
x = > Closed + = x ,
x = > Closed - = x )
. Take ( 1 )
. Subscribe ( _ = >
{
_ modalSubscription ? . Dispose ( ) ;
} ) ,
Disposable . Create ( ( ) = >
{
_ modalSubscription = null ;
owner ! . Activate ( ) ;
tcs . SetResult ( ( TResult ) ( _d ialogResult ? ? default ( TResult ) ! ) ) ;
} ) ;
} )
] ) ;
_ modalSubscription = disposables ;
result = tcs . Task ;
}
OnOpened ( EventArgs . Empty ) ;
if ( ! modal )
_ wasShownBefore = true ;
return result ;
}
}