我有 2 个带分离器的相同网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0" />
<Button Grid.Row="2" />
<GridSplitter Grid.Row="1" Height="4" HorizontalAlignment="Stretch" />
</Grid>
如何让它们同步调整大小?这样两个网格的行高将相同。
最佳答案
看起来我可以通过简单的绑定(bind)来做到这一点:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Path=MySize, Mode=TwoWay}" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0" />
<Button Grid.Row="2" />
<GridSplitter Grid.Row="1" Height="4" HorizontalAlignment="Stretch" />
</Grid>
MySize 在哪里
private GridLength mySize;
public GridLength MySize
{
get { return mySize; }
set
{
if (mySize == value) return;
mySize = value;
OnPropertyChanged("MySize");
}
}
注意: Mode=TwoWay 是必需的,因为与其他控件不同,RowDefinition 不会将其模式默认为 TwoWay
关于c# - 如何绑定(bind)网格行高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8326118/