这是我的 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>
这给我这个错误:
Two-way binding requires Path or XPath.
是什么原因造成的,我该如何解决?
最佳答案
正如错误信息所说,您需要设置绑定(bind)的路径。要直接绑定(bind)到 Source 对象,您可以设置 Path="."
:
<Binding Path="." Source="{StaticResource fixedValue}"/>
也就是说,您的 MultiBinding 可能会被普通的 Binding 替换,其中 fixedValue
作为 ConverterParameter 传递
<TextBox Text="{Binding Path=RM.SpecificGravity,
Converter={StaticResource DoubleConverter},
ConverterParameter=2}" />
像这样的值转换器:
public class DoubleConverter : IValueConverter
{
public object Convert(
object value, Type targetType, object parameter, CultureInfo culture)
{
var p = double.Parse(parameter.ToString());
...
}
...
}
关于xaml - 转换器参数多绑定(bind)静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893235/