Nested MultiBinding(s)

If you have a converter that takes a parameter, you can do something like this:

  • Create a class for passing the "fixed" data to your converter
  • Add DependencyProperties to the class (so that you can bind the values in Xaml)
  • In your xaml, use a binding with a converter instead of a multibinding, something like this:

    <MultiBinding>
        <Binding Source="SomeObject" Path="CoreValue" Converter="{StaticResource YourNewConverter}">
            <Binding.ConverterParameter>
                <ns:ParameterClass Value1="{Binding Parameter1}" Value2="{Binding Parameter1}" />
            </Binding.ConverterParameter>
        </Binding>
     .... 
    

The limitation is that (AFAIK) the value will only be recalculated if CoreValue changes - it won't automatically rebind if the converter parameters change.

(Apologies for any errors, I'm typing this without the benefit of VS to test in...)


I realise that this is an old question now, but I just hit exactly the same problem as the OP. Fortunately in my case I could bind to a sub-element where the result of the multi-binding was already being calculated, but it got me thinking...

A (though admittedly not very clean) solution would be to write the value of the multi-value binding into a 'spare' property such as an element's 'Tag' which you can then reference in your other multi-value bindings by specifying the 'ElementName' attribute.

If you need more than a single nested multi-value binding then you could create a 'fake' object with some dependency properties on it to store multiple intermediate results.

A pity that Microsoft don't implement a properly nested system...


An alternative to the other suggestions is to use attached properties to hold nested MultiBindings as intermediate values.

For example, instead of:

<Element>
  <Element.Property>
    <MultiBinding>
      <Binding Path="A" />       
      <MultiBinding>
        <Binding Path="B" />
        <Binding Path="C" />
      </MultiBinding>
    </MultiBinding>
  </Element.Property>
</Element>

...do this:

<Element Name="ElementName">
  <ElementProperties.AttachedProperty>
    <MultiBinding>
      <Binding Path="B" />
      <Binding Path="C" />
    </MultiBinding>
  </ElementProperties.AttachedProperty>
  <Element.Property>
    <MultiBinding>
      <Binding Path="A" />       
      <Binding ElementName="ElementName" Path="(ElementProperties.AttachedProperty)" />
    </MultiBinding>
  </Element.Property>
</Element>

I know this question is more than six years old now, but I ran into it so someone else will, too.