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...
I know that this is an old question but I think this this is a much nicer approach:
<FrameworkElement x:Name="IsBuyAndAmountInReference"> <FrameworkElement.Tag> <MultiBinding Converter="{StaticResource LogicAndToBool}"> <Binding Path="OrderData.IsBuy" /> <Binding Path="OrderData.AmountInReference" /> </MultiBinding> </FrameworkElement.Tag></FrameworkElement><FrameworkElement x:Name="IsSellAndAmountInBase"> <FrameworkElement.Tag> <MultiBinding Converter="{StaticResource LogicAndToBool}"> <Binding Path="OrderData.IsBuy" Converter="{StaticResource BooleanToBooleanInvert}" /> <Binding Path="OrderData.AmountInReference" Converter="{StaticResource BooleanToBooleanInvert}" /> </MultiBinding> </FrameworkElement.Tag></FrameworkElement><Slider Grid.Row="2" Grid.ColumnSpan="4"> <Slider.Visibility> <MultiBinding Converter="{StaticResource LogicOrToVisibility}"> <Binding ElementName="IsBuyAndAmountInReference" Path="Tag" /> <Binding ElementName="IsSellAndAmountInBase" Path="Tag" /> </MultiBinding> </Slider.Visibility></Slider>