0
votes

I'm trying to set the converter parameter to a property of an item inside an ItemTemplate. Since ConverterParameter is not a dependency property Binding doesn't work.
But I don't really need a binding, just setting it once would be enough since it never changes.

<ItemsControl ItemsSource="ItemsWithTypeProperty">
 <ItemsControl.ItemTemplate>
  <DataTemplate>
   <RadioButton IsChecked="{Binding SelectedItem.Base.Type, Converter={l:IsEqualConverter}, Mode=TwoWay, ConverterParameter={Type}}" />
  </DataTemplate>
 </ItemsControl.ItemTemplate>
</ItemsControl>

IsEqualConverter:
Convert: compares the value to the parameter and returns the result
ConvertBack: If the value is true it returns the parameter

The DataContext of the ItemTemplate is a class which contains the Property with the name "Type".
Its type is object.

Is there a way to replace {Type} with something that would just set it to (DataContext.)Type once? If yes how?

2

2 Answers

1
votes

I'm not sure what exactly Type is. Is it the System.Type of the object? Is it always a fixed type? You could write something like:

ConverterParameter={x:Type local:TypeToCompare}

If Type isn't a constant, you could re-write your converter to implement IMultiValueConverter and use a MultiBinding.

0
votes

Try to use this :

......, ConverterParameter=Type}" />

And on your Converter :

    if ((string)parameter == "Type"))
    {
        //Do some stuff
    }