codymanix
codymanix

Reputation: 29468

WPF: StackPanel item auto-height question

I have a Stackpanel and want that the items automatically set their sizes regarding to their contents but the items should not automatically fill the height of the Stackpanel (But Stackpanel should have auto height according to largest item). I also tried WrapPanel which has the same problem.

I want the TextBox "test" be be vertically centered and automatically sized depending on its text.

                    <TextBox Name="test" VerticalContentAlignment="Center">test</TextBox>

                    <StackPanel  Name="ParameterList" Orientation="Vertical">

                            <TextBox Name="ParamComment" Foreground="Gray">no comment..</TextBox>


                            <TextBox Name="ParamComment2" Foreground="Gray">no comment..</TextBox>
                    </StackPanel>                                               
                </WrapPanel>

Upvotes: 2

Views: 5494

Answers (1)

Botz3000
Botz3000

Reputation: 39600

you mean like this?

    |stackpanelitem
test|stackpanelitem
    |stackpanelitem

then try this:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="*"/>
  </Grid.ColumnDefinitions>
  <TextBox VerticalAlignment="Center" Text="test"/>
  <StackPanel Grid.Column="1">
    <TextBox Text="stackpanelitem"/>
    <!-- other items -->
  </StackPanel>
</Grid>

Upvotes: 3

Related Questions