Here is a simple WPF converter method designed, where the object is a string, and the parameters are a string, which contain a set of comma separated values. The program return true if the list has the value in and false otherwise.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
string temp = parameter as string;
List<String> list = temp.Split(',').ToList();
string x = value as string;
return list.Contains(x);
}
catch (Exception)
{
throw;
}
}
Why I am doing this
I was making a WPF Tab Controller, that looks at the type of objects that it can load and opens up different views based on that information. I cannot change the types of stations that are being supplied to me. Several of these stations share a view between all of them even though their type is different, I am using this converter in a Data Trigger in order to show the same view for this list of stations.
<DataTrigger Binding="{Binding StationState.StationType, Converter={StaticResource BindingInListConvertor}, ConverterParameter={StaticResource FinishingString}}" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource FinishingTemplate}" />
</DataTrigger>
The only other ways I could think of to do this are a multibinding data-trigger, or just a whole lot of them, and figured this would be best because the the possibility of future functionality.
This is my solution for it, is their a better/simpler/cooler way to acomplish this, thanks.