10

is it possible to add a Binding to a ConverterParameter in a MultiBinding? Something like this:

    <HierarchicalDataTemplate DataType="{x:Type Elements:RootElement}">
        <HierarchicalDataTemplate.ItemsSource>
            <MultiBinding Converter="{StaticResource filterConverter}" ConverterParameter="{Binding IsFilterd}">
                <Binding Path="Children"/>
                <Binding Path="FilterChildren"/>
            </MultiBinding>
        </HierarchicalDataTemplate.ItemsSource>
        <TextBlock Text="{Binding Name}" FontWeight="Normal"/>
    </HierarchicalDataTemplate>

Where IsFiltered is a Property on the Object that the Template is applied on. I always get an XAML parser error that the Binding is not correct/allowed in ConverterParameter... Or is there some other way to do this??

Greets,

Jürgen

opiswahn
  • 435
  • 1
  • 5
  • 17

2 Answers2

13

ConverterParameter is not a DependencyProperty, and therefore databinding can't work on it.

Why not add another Binding to the MultiBinding? send the IsFiltered as another value:

        <MultiBinding Converter="{StaticResource filterConverter}" >
            <Binding Path="Children"/>
            <Binding Path="FilterChildren"/>
            <Binding Path="IsFiltered" />
        </MultiBinding>
Elad Katz
  • 7,483
  • 5
  • 35
  • 66
  • @Elad Katz I Actually have a situation , i need to bind a tow way property and have another play a role in the conversion but i can't have a to way binding for the other property , so i need it as a parameter . – eran otzap Apr 11 '13 at 16:51
2

Just add the ConverterParameter the way I did it in the code below, if you have plain text to pass to the multiconverter.

<MultiBinding Converter="{StaticResource SortingDirectionImageMultiConverter}">
    <Binding Path="SortingColumnIdentifier"/>
    <Binding Path="IsSortingAscending"/>
    <MultiBinding.ConverterParameter>txtBlockConfigNumber</MultiBinding.ConverterParameter>
</MultiBinding>
  • While this code snippet may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) helps to improve the quality of your response. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Stefan Crain Feb 19 '19 at 14:05
  • You're right, I added a little comment. I think it's now self explaining. – Michael Bernhard Feb 20 '19 at 13:33