Browse Source

Ensure Window.Width/Height is initialized.

- Run resize logic if `Width`/`Height` are still NaN (i.e. not set up)
- Always call base class `WindowBase.HandleResize`
- In `WindowBase.HandleResize` don't run a layout pass if client size unchanged

Fixes `Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_Manual`.
pull/8232/head
Steven Kirk 4 years ago
parent
commit
138be304a0
  1. 40
      src/Avalonia.Controls/Window.cs
  2. 12
      src/Avalonia.Controls/WindowBase.cs

40
src/Avalonia.Controls/Window.cs

@ -991,28 +991,28 @@ namespace Avalonia.Controls
/// <inheritdoc/>
protected sealed override void HandleResized(Size clientSize, PlatformResizeReason reason)
{
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)
if (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height))
{
if (clientSize.Width != ClientSize.Width)
sizeToContent &= ~SizeToContent.Width;
if (clientSize.Height != ClientSize.Height)
sizeToContent &= ~SizeToContent.Height;
SizeToContent = sizeToContent;
}
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)
{
if (clientSize.Width != ClientSize.Width)
sizeToContent &= ~SizeToContent.Width;
if (clientSize.Height != ClientSize.Height)
sizeToContent &= ~SizeToContent.Height;
SizeToContent = sizeToContent;
}
Width = clientSize.Width;
Height = clientSize.Height;
Width = clientSize.Width;
Height = clientSize.Height;
}
base.HandleResized(clientSize, reason);
}

12
src/Avalonia.Controls/WindowBase.cs

@ -217,10 +217,16 @@ namespace Avalonia.Controls
/// <param name="reason">The reason for the resize.</param>
protected override void HandleResized(Size clientSize, PlatformResizeReason reason)
{
ClientSize = clientSize;
FrameSize = PlatformImpl?.FrameSize;
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
if (ClientSize != clientSize)
{
ClientSize = clientSize;
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
}
System.Diagnostics.Debug.WriteLine($"HandleResized: ClientSize {ClientSize} | FrameSize {FrameSize}");
}
/// <summary>

Loading…
Cancel
Save