WPF: StackPanel article autoinstall question

I have a Stackpanel and want the elements to auto-size themselves in relation to their content, but the elements should not automatically fill the height of the Stackpanel (but the Stackpanel should be auto-sized to match the largest element). I also tried WrapPanel which has the same problem.

I want the TextBox "test" to be vertically centered and auto-fit based 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


source to share


1 answer


do you mean this?

    |stackpanelitem
test|stackpanelitem
    |stackpanelitem

      



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>

      

+3


source







All Articles