我认为问题在于您的源属性Height
是 double 类型并且RowDefinition.Height
是 类型GridLength
。使用转换器,它会双向工作
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Path=Height,
Mode=TwoWay,
Converter={StaticResource DoubleGridLengthConverter}}"/>
<!--...-->
</Grid.RowDefinitions>
DoubleGridLength 转换器
public class DoubleGridLengthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new GridLength((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
GridLength gridLength = (GridLength)value;
return gridLength.Value;
}
}
更新
在这里上传了我的示例应用程序:http ://www.mediafire.com/download.php?pgibb205d65596q
RowDefinition.Height
通过在下部输入一个值来设置TextBox
并RowDefinition.Height
使用GridSplitter