Reputation: 29009
At the start of my xaml page I define converters like this:
<Grid>
<Grid.Resources>
<l:MyMagicConverter x:Key="magicConverter"/>
</Grid.Resources>
Is there a way to add some parameter for the converter to this definition? Like a DependencyProperty, or maybe something simpler? Something like this:
<l:MyMagicConverter x:Key="magicConverter" MyParameter="{Binding MyValue}"/>
I'm aware of the converterparameter when using it, but I'd like to add something in the definition, too.
Upvotes: 1
Views: 95
Reputation: 31721
One can add properties to the converter and then access them in Xaml.
public class RadioButtonToIntConverter : IValueConverter
{
public string ABC { get; set; }
Xaml:
<reportConverters:RadioButtonToIntConverter x:Key="RadioButtonToIntConverter"
ABC="def" />
Now what you are binding it to, as to a static resource may be a problem.
As an aside, if one does not want to have to directly instantiate the converter in xaml, I provide a way to automatically hook up a converter without that xaml instantiation.
I suggest this as a way to instantiate the target converter which has 'pre-baked' properties which you might want to use.
Upvotes: 2