Reputation: 674
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?
Upvotes: 0
Views: 974
Reputation: 1576
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.
Upvotes: 1
Reputation: 141
Try to use this :
......, ConverterParameter=Type}" />
And on your Converter :
if ((string)parameter == "Type"))
{
//Do some stuff
}
Upvotes: 0