Question

I have a WPF treeview used to display a file structure. Each treeitem has a collection of enums to determine custom status' of the item. I.E. ObservableCollection<enumType> statusCollection;

I have several ellipses that are displayed when a treeitem has one of these status... something like this:

<Ellipse Margin="3,0" Visibility="{Binding StatusCollection, Converter={StaticResource VisibilityConverter}}" StrokeThickness="1" Stroke="Black" Width="12" Height="12" Fill="Red" />

Is there a way I can use the same Converter for multiple ellipses to check for a specific status... via an argument perhaps? Right now in the Converter, i loop through the collection looking for the specific enum... doing this, I would have to create a new Converter for each enum created, which is not ideal.

Better yet, how would I go about dynamically creating Ellipses for each status in a treeviewitem?

Was it helpful?

Solution

You could add a ConverterParameter to the Binding:

Visibility="{Binding StatusCollection,
      Converter={StaticResource VisibilityConverter},
      ConverterParameter={x:Static local:MyEnumType.EnumValue}}"

This will then be passed into your IValueConverter as the parameter (third parameter) in

Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

You can then use the parameter within your converter however you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top