WPF: Binding the height of a component to another's

前端 未结 2 795
庸人自扰
庸人自扰 2020-12-29 05:25

I have, in a window, a Grid that contains a RadioButton, a TextBox and a Button, each in column 0, 1, 2, respectively. Th

相关标签:
2条回答
  • 2020-12-29 06:06

    Put the two grids in a shared size scope, and use SharedSizeGroup to lock the row heights together:

    <SomeContainer Grid.IsSharedSizeScope="True">  <!-- Could be the Window or some more nearby Panel -->
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition SharedSizeGroup="LabelAndRadioButtonGroup" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" />
      </Grid>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition SharedSizeGroup="LabelAndRadioButtonGroup" />
        </Grid.RowDefinitions>
        <RadioButton Grid.Row="0" />
      </Grid>
    </SomeContainer>
    

    See also How to: Share sizing properties between grids in MSDN.

    0 讨论(0)
  • 2020-12-29 06:19

    Bind to the ActualHeight rather than the Height property:

    <RowDefinition Height="{Binding ActualHeight, ElementName=otherTextBox}" />
    
    0 讨论(0)
提交回复
热议问题