1

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.

1 Answer 1

2

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.

Xaml: Call Binding Converter Without Defining StaticResource in Xaml Thanks to Markup Derived Base Class in C#

I suggest this as a way to instantiate the target converter which has 'pre-baked' properties which you might want to use.

Not the answer you're looking for? Browse other questions tagged or ask your own question.