我有以下转换器:
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
...
然后我在XAML中使用它如下:
<Resources>
<conv:MyConverter x:Key="MyValToVisibilityConverter" />
</Resources>
...
<CheckBox x:Name="MyCheckBox" Content="Should not be visible"
Visibility="{Binding ElementName=Visibility, Converter={StaticResource MyValToVisibilityConverter}}"
...
这会编译并运行,并始终将复选框显示为可见。
答案 0 :(得分:3)
您正在为绑定设置错误的参数。
现在,绑定目标是一个名为Visibility
的元素,很可能是一个错误:
Visibility="{Binding ElementName=Visibility, Converter={...}}"
应该只是
Visibility="{Binding Converter={...}}"