File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
tests/Avalonia.Controls.UnitTests Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -918,6 +918,15 @@ protected override Size MeasureOverride(Size availableSize)
918
918
var constraint = clientSize ;
919
919
var maxAutoSize = PlatformImpl ? . MaxAutoSizeHint ?? Size . Infinity ;
920
920
921
+ if ( MaxWidth > 0 && MaxWidth < maxAutoSize . Width )
922
+ {
923
+ maxAutoSize = maxAutoSize . WithWidth ( MaxWidth ) ;
924
+ }
925
+ if ( MaxHeight > 0 && MaxHeight < maxAutoSize . Height )
926
+ {
927
+ maxAutoSize = maxAutoSize . WithHeight ( MaxHeight ) ;
928
+ }
929
+
921
930
if ( sizeToContent . HasAllFlags ( SizeToContent . Width ) )
922
931
{
923
932
constraint = constraint . WithWidth ( maxAutoSize . Width ) ;
Original file line number Diff line number Diff line change @@ -719,6 +719,27 @@ public void Width_Height_Should_Not_Be_NaN_After_Show_With_SizeToContent_WidthAn
719
719
}
720
720
}
721
721
722
+ [ Fact ]
723
+ public void MaxWidth_And_MaxHeight_Should_Be_Respected_With_SizeToContent_WidthAndHeight ( )
724
+ {
725
+ using ( UnitTestApplication . Start ( TestServices . StyledWindow ) )
726
+ {
727
+ var child = new ChildControl ( ) ;
728
+
729
+ var target = new Window ( )
730
+ {
731
+ SizeToContent = SizeToContent . WidthAndHeight ,
732
+ MaxWidth = 300 ,
733
+ MaxHeight = 700 ,
734
+ Content = child ,
735
+ } ;
736
+
737
+ Show ( target ) ;
738
+
739
+ Assert . Equal ( new [ ] { new Size ( 300 , 700 ) } , child . MeasureSizes ) ;
740
+ }
741
+ }
742
+
722
743
[ Fact ]
723
744
public void SizeToContent_Should_Not_Be_Lost_On_Show ( )
724
745
{
You can’t perform that action at this time.
0 commit comments