Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried to simplify your code a bit:</p> <pre><code>public class CustomPanel:Panel { protected override Size MeasureOverride(Size availableSize) { foreach (UIElement child in Children) child.Measure(new Size(double.PositiveInfinity,double.PositiveInfinity)); return new Size(0,0); } protected override Size ArrangeOverride(Size finalSize) { double remainingSpace = Math.Max(0.0,finalSize.Height - Children.Cast&lt;UIElement&gt;().Sum(c =&gt; c.DesiredSize.Height)); var extraSpace = remainingSpace / Children.Count; double offset = 0.0; foreach (UIElement child in Children) { double height = child.DesiredSize.Height + extraSpace; child.Arrange(new Rect(0, offset, finalSize.Width, height)); offset += height; } return finalSize; } } </code></pre> <p>A few notes:</p> <ul> <li>You shouldn't return available size in MeasureOverride - it could be positive infinity which will cause an exception. And since you basically don't care what size it is, just return new Size(0,0).</li> <li>As for your problem with the height of the children - I'm thinking it has to do with the actual children - are they limited in size somehow via Style or properties in regards to HorizontalAlignment?</li> </ul> <p>EDIT: version 2.0:</p> <pre><code> public class CustomPanel : Panel { protected override Size MeasureOverride(Size availableSize) { foreach (UIElement child in Children) child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); return new Size(0, 0); } protected override Size ArrangeOverride(Size finalSize) { double optimumHeight = finalSize.Height / Children.Count; var smallElements = Children.Cast&lt;UIElement&gt;().Where(c =&gt; c.DesiredSize.Height &lt; optimumHeight); double leftOverHeight = smallElements.Sum(c =&gt; optimumHeight - c.DesiredSize.Height); var extraSpaceForBigElements = leftOverHeight / (Children.Count - smallElements.Count()); double offset = 0.0; foreach (UIElement child in Children) { double height = child.DesiredSize.Height &lt; optimumHeight ? child.DesiredSize.Height : optimumHeight + extraSpaceForBigElements; child.Arrange(new Rect(0, offset, finalSize.Width, height)); offset += height; } return finalSize; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload