我正在使用多值轉換器來獲取行的高度。但我在高度綁定(通過snoop看到)上得到以下錯誤。轉換器不能用於行定義高度
System.Windows.Data錯誤:5:由BindingExpression生成的值對目標屬性無效。值= '33 .44444'MultibindingBindingExpression:目標元素是'RowDefinition'。目標屬性是'高度'(類型'GridLength')
即使經過Google搜索,我也無法解決這個問題。任何人都可以請幫我解決這個問題。
我行定義:
<Grid.RowDefinitions>
<RowDefinition>
<RowDefinition.Height>
<MultiBinding
Converter="{StaticResource HeightConverter}">
<Binding Path="Height"
RelativeSource="{RelativeSource AncestorType=controls:TestControl,
Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding>
<Binding Path="MR"
RelativeSource="{RelativeSource AncestorType=controls:TestControl,
Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding>
<Binding Path="BR"
RelativeSource="{RelativeSource AncestorType=controls:TestControl,
Mode=FindAncestor}" UpdateSourceTrigger="PropertyChanged"></Binding>
</MultiBinding>
</RowDefinition.Height>
</RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
我的身高轉換代碼:
public object Convert(object[] values, Type targetType, object
parameter, CultureInfo culture)
{
var TH = (double)values[0];
var TR = (double)values[1];
var BR = (double)values[2];
var per = TR + BR;
var per2 = (TR/per)*100;
return (int)(per2/TH)*100;
}
感謝&問候
是否結合'ActualHeight'任何工作比'Height'更好? 'Height'在運行時通常不會改變,所以''Binding'不會醒來。 –