I am trying to set up the visibility property on a control so that it is visible when the bound value is matches an arbitrary value.
I have set up my converter as a static resource
Applied the binding
<Button Content="Foo" Visibility="{Binding SelectedValue, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='1,2'}" />
But am met with the error
Error 1 '{Binding SelectedValue, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='1,2'}' cannot be used as a value for 'Visibility'. Numbers are not valid enumeration values.
My converter code is
public class ValueToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture)
{
if (value == null || parameter == null || !(value is String))
return Visibility.Collapsed;
var currentValue = value.ToString();
var matchStrings = parameter.ToString();
var found = false;
foreach (var state in matchStrings.Split(','))
{
found = (currentValue == state.Trim());
if (found)
break;
}
return found ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
The error stops compile and feels like it is trying to be too clever and is ignoring my converter.
Have I applied it wrong or am otherwise ignorant of some process going on.
EDIT:
To get the converter as a static resource I have the below in my window definition
xmlns:myConverters="clr-namespace:<namespace>;assembly=<assemblyname>"
And this in my window resources, right along side the same code for other converters that work perfectly
<myConverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />