这是我的 XAML 代码:
<TextBox HorizontalAlignment="Left" Height="24" Margin="168,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="280">
<TextBox.Resources>
<sys:Double x:Key="fixedValue">2</sys:Double>
</TextBox.Resources>
<TextBox.Text>
<MultiBinding Converter="{StaticResource DoubleConverter}">
<Binding Path="RM.SpecificGravity"/>
<Binding Source="{StaticResource fixedValue}"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
双向绑定需要 Path 或 XPath。
这是什么原因造成的,我该如何解决?
正如错误消息所说,您需要设置绑定的路径。要直接绑定到 Source 对象,您可以设置Path=".":
<Binding Path="." Source="{StaticResource fixedValue}"/>
Run Code Online (Sandbox Code Playgroud)
也就是说,您的 MultiBinding 可能会被普通的 Binding 替换,其中将fixedValue作为 ConverterParameter 传递
<TextBox Text="{Binding Path=RM.SpecificGravity,
Converter={StaticResource DoubleConverter},
ConverterParameter=2}" />
Run Code Online (Sandbox Code Playgroud)
使用这样的值转换器:
public class DoubleConverter : IValueConverter
{
public object Convert(
object value, Type targetType, object parameter, CultureInfo culture)
{
var p = double.Parse(parameter.ToString());
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1596 次 |
| 最近记录: |