@ -244,7 +244,7 @@ namespace Avalonia.Controls
impl . WindowStateChanged = HandleWindowStateChanged ;
_ maxPlatformClientSize = PlatformImpl ? . MaxAutoSizeHint ? ? default ( Size ) ;
impl . ExtendClientAreaToDecorationsChanged = ExtendClientAreaToDecorationsChanged ;
this . GetObservable ( ClientSizeProperty ) . Skip ( 1 ) . Subscribe ( x = > PlatformImpl ? . Resize ( x ) ) ;
this . GetObservable ( ClientSizeProperty ) . Skip ( 1 ) . Subscribe ( x = > PlatformImpl ? . Resize ( x , PlatformResizeReason . Application ) ) ;
PlatformImpl ? . ShowTaskbarIcon ( ShowInTaskbar ) ;
}
@ -258,6 +258,18 @@ namespace Avalonia.Controls
/// <summary>
/// Gets or sets a value indicating how the window will size itself to fit its content.
/// </summary>
/// <remarks>
/// If <see cref="SizeToContent"/> has a value other than <see cref="SizeToContent.Manual"/>,
/// <see cref="SizeToContent"/> is automatically set to <see cref="SizeToContent.Manual"/>
/// if a user resizes the window by using the resize grip or dragging the border.
///
/// NOTE: Because of a limitation of X11, <see cref="SizeToContent"/> will be reset on X11 to
/// <see cref="SizeToContent.Manual"/> on any resize - including the resize that happens when
/// the window is first shown. This is because X11 resize notifications are asynchronous and
/// there is no way to know whether a resize came from the user or the layout system. To avoid
/// this, consider setting <see cref="CanResize"/> to false, which will disable user resizing
/// of the window.
/// </remarks>
public SizeToContent SizeToContent
{
get { return GetValue ( SizeToContentProperty ) ; }
@ -583,28 +595,23 @@ namespace Avalonia.Controls
return ;
}
using ( BeginAutoSizing ( ) )
{
Renderer ? . Stop ( ) ;
Renderer ? . Stop ( ) ;
if ( Owner is Window owner )
{
owner . RemoveChild ( this ) ;
}
if ( Owner is Window owner )
{
owner . RemoveChild ( this ) ;
}
if ( _ children . Count > 0 )
if ( _ children . Count > 0 )
{
foreach ( var child in _ children . ToArray ( ) )
{
foreach ( var child in _ children . ToArray ( ) )
{
child . child . Hide ( ) ;
}
child . child . Hide ( ) ;
}
Owner = null ;
PlatformImpl ? . Hide ( ) ;
}
Owner = null ;
PlatformImpl ? . Hide ( ) ;
IsVisible = false ;
}
@ -675,29 +682,23 @@ namespace Avalonia.Controls
if ( initialSize ! = ClientSize )
{
using ( BeginAutoSizing ( ) )
{
PlatformImpl ? . Resize ( initialSize ) ;
}
PlatformImpl ? . Resize ( initialSize , PlatformResizeReason . Layout ) ;
}
LayoutManager . ExecuteInitialLayoutPass ( ) ;
using ( BeginAutoSizing ( ) )
if ( parent ! = null )
{
if ( parent ! = null )
{
PlatformImpl ? . SetParent ( parent . PlatformImpl ) ;
}
Owner = parent ;
parent ? . AddChild ( this , false ) ;
SetWindowStartupLocation ( Owner ? . PlatformImpl ) ;
PlatformImpl ? . Show ( ShowActivated ) ;
Renderer ? . Start ( ) ;
PlatformImpl ? . SetParent ( parent . PlatformImpl ) ;
}
Owner = parent ;
parent ? . AddChild ( this , false ) ;
SetWindowStartupLocation ( Owner ? . PlatformImpl ) ;
PlatformImpl ? . Show ( ShowActivated ) ;
Renderer ? . Start ( ) ;
OnOpened ( EventArgs . Empty ) ;
}
@ -760,41 +761,34 @@ namespace Avalonia.Controls
if ( initialSize ! = ClientSize )
{
using ( BeginAutoSizing ( ) )
{
PlatformImpl ? . Resize ( initialSize ) ;
}
PlatformImpl ? . Resize ( initialSize , PlatformResizeReason . Layout ) ;
}
LayoutManager . ExecuteInitialLayoutPass ( ) ;
var result = new TaskCompletionSource < TResult > ( ) ;
using ( BeginAutoSizing ( ) )
{
PlatformImpl ? . SetParent ( owner . PlatformImpl ) ;
Owner = owner ;
owner . AddChild ( this , true ) ;
SetWindowStartupLocation ( owner . PlatformImpl ) ;
PlatformImpl ? . Show ( ShowActivated ) ;
PlatformImpl ? . SetParent ( owner . PlatformImpl ) ;
Owner = owner ;
owner . AddChild ( this , true ) ;
Renderer ? . Start ( ) ;
SetWindowStartupLocation ( owner . PlatformImpl ) ;
Observable . FromEventPattern < EventHandler , EventArgs > (
x = > Closed + = x ,
x = > Closed - = x )
. Take ( 1 )
. Subscribe ( _ = >
{
owner . Activate ( ) ;
result . SetResult ( ( TResult ) ( _d ialogResult ? ? default ( TResult ) ) ) ;
} ) ;
PlatformImpl ? . Show ( ShowActivated ) ;
OnOpened ( EventArgs . Empty ) ;
}
Renderer ? . Start ( ) ;
Observable . FromEventPattern < EventHandler , EventArgs > (
x = > Closed + = x ,
x = > Closed - = x )
. Take ( 1 )
. Subscribe ( _ = >
{
owner . Activate ( ) ;
result . SetResult ( ( TResult ) ( _d ialogResult ? ? default ( TResult ) ) ) ;
} ) ;
OnOpened ( EventArgs . Empty ) ;
return result . Task ;
}
@ -937,11 +931,8 @@ namespace Avalonia.Controls
protected sealed override Size ArrangeSetBounds ( Size size )
{
using ( BeginAutoSizing ( ) )
{
PlatformImpl ? . Resize ( size ) ;
return ClientSize ;
}
PlatformImpl ? . Resize ( size , PlatformResizeReason . Layout ) ;
return ClientSize ;
}
protected sealed override void HandleClosed ( )
@ -959,17 +950,32 @@ namespace Avalonia.Controls
}
/// <inheritdoc/>
protected sealed override void HandleResized ( Size clientSize )
protected sealed override void HandleResized ( Size clientSize , PlatformResizeReason reason )
{
if ( ! AutoSizing )
if ( ClientSize = = clientSize )
return ;
var sizeToContent = SizeToContent ;
// If auto-sizing is enabled, and the resize came from a user resize (or the reason was
// unspecified) then turn off auto-resizing for any window dimension that is not equal
// to the requested size.
if ( sizeToContent ! = SizeToContent . Manual & &
CanResize & &
reason = = PlatformResizeReason . Unspecified | |
reason = = PlatformResizeReason . User )
{
SizeToContent = SizeToContent . Manual ;
if ( clientSize . Width ! = ClientSize . Width )
sizeToContent & = ~ SizeToContent . Width ;
if ( clientSize . Height ! = ClientSize . Height )
sizeToContent & = ~ SizeToContent . Height ;
SizeToContent = sizeToContent ;
}
Width = clientSize . Width ;
Height = clientSize . Height ;
base . HandleResized ( clientSize ) ;
base . HandleResized ( clientSize , reason ) ;
}
/// <summary>