我正在尝试绑定(bind)到整数属性:
<RadioButton Content="None"
IsChecked="{Binding MyProperty,
Converter={StaticResource IntToBoolConverter},
ConverterParameter=0}" />
我的转换器是:
[ValueConversion(typeof(int), typeof(bool))]
public class IntToBoolConverter : IValueConverter
{
public object Convert(object value, Type t, object parameter, CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type t, object parameter, CultureInfo culture)
{
return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
}
}
问题是当我的转换器被调用时参数是字符串。我需要它是一个整数。我当然可以解析字符串,但是我必须这样做吗?
感谢您的帮助 康斯坦丁
最佳答案
给你!
<RadioButton Content="None"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<RadioButton.IsChecked>
<Binding Path="MyProperty"
Converter="{StaticResource IntToBoolConverter}">
<Binding.ConverterParameter>
<sys:Int32>0</sys:Int32>
</Binding.ConverterParameter>
</Binding>
</RadioButton.IsChecked>
</RadioButton>
诀窍是包含基本系统类型的命名空间,然后至少以元素形式编写 ConverterParameter 绑定(bind)。
关于wpf - 如何传递整数作为 ConverterParameter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3978937/