Silverlight - How do I make each item in a list box be the same height?

Posted by NotDan on Stack Overflow See other posts from Stack Overflow or by NotDan
Published on 2009-07-23T16:09:56Z Indexed on 2010/03/13 10:25 UTC
Read the original article Hit count: 401

Filed under:
|
|
|

How can I make a silverlight listbox have all items be the same size and have them take up 100% of the listbox height. I.e. 1 item would be the height of the listbox, 2 items would each be 50% of the height of the list box, etc...

Edit - Here is the code

public class UniformPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        Size panelDesiredSize = new Size();

        for (int i = 0; i < Children.Count; i++)
        {
            UIElement child = Children[i];
            child.Measure(availableSize);
            var childDesiredSize = child.DesiredSize;
            panelDesiredSize.Height += childDesiredSize.Height;
            if (panelDesiredSize.Width < childDesiredSize.Width)
            {
                panelDesiredSize.Width = childDesiredSize.Width;
            }
        }

        return panelDesiredSize;
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        double height = finalSize.Height/Children.Count;
        for (int i = 0; i < Children.Count; i++)
        {
            UIElement child = Children[i];
            Size size = new Size(finalSize.Width, height);
            child.Arrange(new Rect(new Point(0, i * height), size));
        }
        return finalSize; // Returns the final Arranged size
    }
}

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about wpf