O'Reilly logo

Microsoft® Silverlight® Edition: Programming Windows® Phone 7 by Charles Petzold

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Custom Vertical StackPanel

The next Panel derivative I’ll show you is the StackPanel, and you’ll see how it differs from the single-cell Grid. To keep the code simple, and to avoid defining properties, I’m going to call this custom class VerticalStackPanel. Here’s the MeasureOverride method:

Example 9-15. Silverlight Project: VerticalStackPanelDemo File: VerticalStackPanel.cs (exerpt)

protected override Size MeasureOverride(Size availableSize)
{
    Size compositeSize = new Size();

    foreach (UIElement child in Children)
    {
        child.Measure(new Size(availableSize.Width, Double.PositiveInfinity));
        compositeSize.Width = Math.Max(compositeSize.Width, child.DesiredSize.Width);
        compositeSize.Height += child.DesiredSize.Height;
    }
    return compositeSize;
}

As usual, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required