#320 – Default Size of StackPanel Child Controls

By default, a StackPanel uses the following logic for sizing its child controls.

If Orientation is vertical

  • Child height set to fit content
  • Child width stretched to fit width of the StackPanel

If Orientation is horizontal

  • Child width set to fit content
  • Child height stretched to fit height of the StackPanel

The example below shows a set of child controls, layed out vertically.

    <StackPanel>
        <Label Content="Gene Autry the singing cowboy" Background="Pink"/>
        <Button Content="I Like Gene" FontSize="18"/>
        <Label Content="Roy Rogers" Background="Aqua" FontSize="20"/>
        <Button Content="I Like Roy Rogers Yes I Do"/>
        <TextBox Text="This is a TextBox"/>

        <Label Content="Tex Ritter" Background="PaleGoldenrod"/>
        <Button Content="I Like Tex" FontSize="20" />
        <Label Content="Jorge Negrete" Background="Lavender"/>
        <Button Content="I Like Jorge Yes I Do"/>
    </StackPanel>

Setting the Orientation to horizontal gives us:

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: