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

雨燕双飞 提交于 2019-12-03 02:31:12
itowlson

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.

itowlson

Bind to the ActualHeight rather than the Height property:

<RowDefinition Height="{Binding ActualHeight, ElementName=otherTextBox}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!