views:

765

answers:

1

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>
+2  A: 

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>
Botz3000
Yes I meant exactly that. Thanks for the answer. Why does StackPanel have Grid.Column="1" but the TextBox does not have Grid.Column="0"? And what is the difference between "Auto" and "*"?
codymanix
As you can see i defined two columns for the grid. Grid.Column is an attached property and just specifies in which column of the grid this control is placed. 0 is the default value, so it is not necessary. Auto means that the column will size automatically to the widest item, * means that it will take all the available space. If i had specified a third column with width *, then the two columns would each use half of the remaining space.
Botz3000