Browse Source
Merge pull request #8095 from sn4k3/master
Respect Window MaxWidth and MaxHeight when using any SizeToContent to Auto
pull/8158/head
Steven Kirk
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
30 additions and
0 deletions
-
src/Avalonia.Controls/Window.cs
-
tests/Avalonia.Controls.UnitTests/WindowTests.cs
|
|
|
@ -917,6 +917,15 @@ namespace Avalonia.Controls |
|
|
|
var constraint = clientSize; |
|
|
|
var maxAutoSize = PlatformImpl?.MaxAutoSizeHint ?? Size.Infinity; |
|
|
|
|
|
|
|
if (MaxWidth > 0 && MaxWidth < maxAutoSize.Width) |
|
|
|
{ |
|
|
|
maxAutoSize = maxAutoSize.WithWidth(MaxWidth); |
|
|
|
} |
|
|
|
if (MaxHeight > 0 && MaxHeight < maxAutoSize.Height) |
|
|
|
{ |
|
|
|
maxAutoSize = maxAutoSize.WithHeight(MaxHeight); |
|
|
|
} |
|
|
|
|
|
|
|
if (sizeToContent.HasAllFlags(SizeToContent.Width)) |
|
|
|
{ |
|
|
|
constraint = constraint.WithWidth(maxAutoSize.Width); |
|
|
|
|
|
|
|
@ -719,6 +719,27 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void MaxWidth_And_MaxHeight_Should_Be_Respected_With_SizeToContent_WidthAndHeight() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var child = new ChildControl(); |
|
|
|
|
|
|
|
var target = new Window() |
|
|
|
{ |
|
|
|
SizeToContent = SizeToContent.WidthAndHeight, |
|
|
|
MaxWidth = 300, |
|
|
|
MaxHeight = 700, |
|
|
|
Content = child, |
|
|
|
}; |
|
|
|
|
|
|
|
Show(target); |
|
|
|
|
|
|
|
Assert.Equal(new[] { new Size(300, 700) }, child.MeasureSizes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SizeToContent_Should_Not_Be_Lost_On_Show() |
|
|
|
{ |
|
|
|
|