@@ -218,7 +218,12 @@ protected override Size MeasureOverride(Size availableSize)
218218 #region Calc AvailableSize
219219
220220 _childGraph . Reset ( false ) ;
221- var boundingSize = _childGraph . GetBoundingSize ( Width . IsNaN ( ) , Height . IsNaN ( ) , availableSize ) ;
221+
222+
223+ var calcWidth = Width . IsNaN ( ) && HorizontalAlignment != HorizontalAlignment . Stretch ;
224+ var calcHeight = Height . IsNaN ( ) && VerticalAlignment != VerticalAlignment . Stretch ;
225+
226+ var boundingSize = _childGraph . GetBoundingSize ( calcWidth , calcHeight ) ;
222227 _childGraph . Reset ( ) ;
223228 _childGraph . Measure ( boundingSize ) ;
224229 return boundingSize ;
@@ -454,8 +459,6 @@ private void Measure(IEnumerable<GraphNode> nodes, HashSet<DependencyObject> set
454459
455460 private void MeasureChild ( GraphNode node )
456461 {
457- var availableSize = AvailableSize ;
458-
459462 var child = node . Element ;
460463 child . Measure ( new Size ( double . PositiveInfinity , double . PositiveInfinity ) ) ;
461464 node . OriginDesiredSize = child . DesiredSize ;
@@ -504,10 +507,10 @@ private void MeasureChild(GraphNode node)
504507
505508 #region Measure
506509
507- var availableHeight = availableSize . Height - node . Top - node . Bottom ;
510+ var availableHeight = AvailableSize . Height - node . Top - node . Bottom ;
508511 if ( availableHeight . IsNaN ( ) )
509512 {
510- availableHeight = availableSize . Height ;
513+ availableHeight = AvailableSize . Height ;
511514
512515 if ( ! node . Top . IsNaN ( ) && node . Bottom . IsNaN ( ) )
513516 {
@@ -519,10 +522,10 @@ private void MeasureChild(GraphNode node)
519522 }
520523 }
521524
522- var availableWidth = availableSize . Width - node . Left - node . Right ;
525+ var availableWidth = AvailableSize . Width - node . Left - node . Right ;
523526 if ( availableWidth . IsNaN ( ) )
524527 {
525- availableWidth = availableSize . Width ;
528+ availableWidth = AvailableSize . Width ;
526529
527530 if ( ! node . Left . IsNaN ( ) && node . Right . IsNaN ( ) )
528531 {
@@ -560,7 +563,7 @@ private void MeasureChild(GraphNode node)
560563
561564 if ( node . Left . IsNaN ( ) )
562565 {
563- node . Left = availableSize . Width - node . RightOfNode . Right ;
566+ node . Left = AvailableSize . Width - node . RightOfNode . Right ;
564567 }
565568 }
566569
@@ -573,7 +576,7 @@ private void MeasureChild(GraphNode node)
573576
574577 if ( node . Top . IsNaN ( ) )
575578 {
576- node . Top = availableSize . Height - node . BelowNode . Bottom ;
579+ node . Top = AvailableSize . Height - node . BelowNode . Bottom ;
577580 }
578581 }
579582
@@ -583,8 +586,8 @@ private void MeasureChild(GraphNode node)
583586
584587 if ( node . AlignHorizontalCenterWith != null )
585588 {
586- var halfWidthLeft = ( availableSize . Width + node . AlignHorizontalCenterWith . Left - node . AlignHorizontalCenterWith . Right - childSize . Width ) * 0.5 ;
587- var halfWidthRight = ( availableSize . Width - node . AlignHorizontalCenterWith . Left + node . AlignHorizontalCenterWith . Right - childSize . Width ) * 0.5 ;
589+ var halfWidthLeft = ( AvailableSize . Width + node . AlignHorizontalCenterWith . Left - node . AlignHorizontalCenterWith . Right - childSize . Width ) * 0.5 ;
590+ var halfWidthRight = ( AvailableSize . Width - node . AlignHorizontalCenterWith . Left + node . AlignHorizontalCenterWith . Right - childSize . Width ) * 0.5 ;
588591
589592 if ( node . Left . IsNaN ( ) ) node . Left = halfWidthLeft ;
590593 else node . Left = ( node . Left + halfWidthLeft ) * 0.5 ;
@@ -595,8 +598,8 @@ private void MeasureChild(GraphNode node)
595598
596599 if ( node . AlignVerticalCenterWith != null )
597600 {
598- var halfHeightTop = ( availableSize . Height + node . AlignVerticalCenterWith . Top - node . AlignVerticalCenterWith . Bottom - childSize . Height ) * 0.5 ;
599- var halfHeightBottom = ( availableSize . Height - node . AlignVerticalCenterWith . Top + node . AlignVerticalCenterWith . Bottom - childSize . Height ) * 0.5 ;
601+ var halfHeightTop = ( AvailableSize . Height + node . AlignVerticalCenterWith . Top - node . AlignVerticalCenterWith . Bottom - childSize . Height ) * 0.5 ;
602+ var halfHeightBottom = ( AvailableSize . Height - node . AlignVerticalCenterWith . Top + node . AlignVerticalCenterWith . Bottom - childSize . Height ) * 0.5 ;
600603
601604 if ( node . Top . IsNaN ( ) ) node . Top = halfHeightTop ;
602605 else node . Top = ( node . Top + halfHeightTop ) * 0.5 ;
@@ -611,7 +614,7 @@ private void MeasureChild(GraphNode node)
611614
612615 if ( GetAlignHorizontalCenterWithPanel ( child ) )
613616 {
614- var halfSubWidth = ( availableSize . Width - childSize . Width ) * 0.5 ;
617+ var halfSubWidth = ( AvailableSize . Width - childSize . Width ) * 0.5 ;
615618
616619 if ( node . Left . IsNaN ( ) ) node . Left = halfSubWidth ;
617620 else node . Left = ( node . Left + halfSubWidth ) * 0.5 ;
@@ -622,7 +625,7 @@ private void MeasureChild(GraphNode node)
622625
623626 if ( GetAlignVerticalCenterWithPanel ( child ) )
624627 {
625- var halfSubHeight = ( availableSize . Height - childSize . Height ) * 0.5 ;
628+ var halfSubHeight = ( AvailableSize . Height - childSize . Height ) * 0.5 ;
626629
627630 if ( node . Top . IsNaN ( ) ) node . Top = halfSubHeight ;
628631 else node . Top = ( node . Top + halfSubHeight ) * 0.5 ;
@@ -636,37 +639,37 @@ private void MeasureChild(GraphNode node)
636639 if ( node . Left . IsNaN ( ) )
637640 {
638641 if ( ! node . Right . IsNaN ( ) )
639- node . Left = availableSize . Width - node . Right - childSize . Width ;
642+ node . Left = AvailableSize . Width - node . Right - childSize . Width ;
640643 else
641644 {
642645 node . Left = 0 ;
643- node . Right = availableSize . Width - childSize . Width ;
646+ node . Right = AvailableSize . Width - childSize . Width ;
644647 }
645648 }
646649 else if ( ! node . Left . IsNaN ( ) && node . Right . IsNaN ( ) )
647650 {
648- node . Right = availableSize . Width - node . Left - childSize . Width ;
651+ node . Right = AvailableSize . Width - node . Left - childSize . Width ;
649652 }
650653
651654 if ( node . Top . IsNaN ( ) )
652655 {
653656 if ( ! node . Bottom . IsNaN ( ) )
654- node . Top = availableSize . Height - node . Bottom - childSize . Height ;
657+ node . Top = AvailableSize . Height - node . Bottom - childSize . Height ;
655658 else
656659 {
657660 node . Top = 0 ;
658- node . Bottom = availableSize . Height - childSize . Height ;
661+ node . Bottom = AvailableSize . Height - childSize . Height ;
659662 }
660663 }
661664 else if ( ! node . Top . IsNaN ( ) && node . Bottom . IsNaN ( ) )
662665 {
663- node . Bottom = availableSize . Height - node . Top - childSize . Height ;
666+ node . Bottom = AvailableSize . Height - node . Top - childSize . Height ;
664667 }
665668
666669 node . Measured = true ;
667670 }
668671
669- public Size GetBoundingSize ( bool calcWidth , bool calcHeight , Size availableSize )
672+ public Size GetBoundingSize ( bool calcWidth , bool calcHeight )
670673 {
671674 var boundingSize = new Size ( ) ;
672675
@@ -677,8 +680,8 @@ public Size GetBoundingSize(bool calcWidth, bool calcHeight, Size availableSize)
677680 boundingSize . Height = Math . Max ( boundingSize . Height , size . Height ) ;
678681 }
679682
680- boundingSize . Width = calcWidth ? Math . Max ( availableSize . Width , boundingSize . Width ) : availableSize . Width ;
681- boundingSize . Height = calcHeight ? Math . Max ( availableSize . Height , boundingSize . Height ) : availableSize . Height ;
683+ boundingSize . Width = calcWidth ? boundingSize . Width : AvailableSize . Width ;
684+ boundingSize . Height = calcHeight ? boundingSize . Height : AvailableSize . Height ;
682685 return boundingSize ;
683686 }
684687 }
0 commit comments