我在网格分割器方面遇到了困难。我已经绑定了RowDefinition.Height
模型的 clr 属性的依赖属性,如下所示。
<Grid.RowDefinitions>
<RowDefinition Height='{Binding Path=Height, Mode=OneWay}' />
<RowDefinition Height='*' />
</Grid.RowDefinitions>
这工作正常直到GridSplitter
用来。当行的高度手动更改时GridSplitter
,它用新的固定大小替换绑定(并删除绑定)。
您是否有任何想法或解决方法如何创建可使用 GridSplitter 调整大小但仍根据 clr 属性/绑定更改其高度的两行?
我认为问题在于你的源属性Height
是 double 类型并且RowDefinition.Height
属于类型GridLength
。使用转换器,它可以双向工作
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Path=Height,
Mode=TwoWay,
Converter={StaticResource DoubleGridLengthConverter}}"/>
<!--...-->
</Grid.RowDefinitions>
双网格长度转换器
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;
}
}
Update
在这里上传了我的示例应用程序:http://www.mediafire.com/download.php?pgibb205d65596q http://www.mediafire.com/download.php?pgibb205d65596q
Set the RowDefinition.Height
通过在较低的值中输入一个值TextBox
并调整大小RowDefinition.Height
与GridSplitter
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)