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
}
}