Converters to Child Bindings in MultiBinding
Suppose I have this MultiBinding:
<MultiBinding Converter="{StaticResource FooBarConverter}>
<Binding Path="Foo" Converter="{StaticResource FooConverter}" />
<Binding Path="Bar" Converter="{StaticResource BarConverter}" />
</MultiBinding>
It doesn't work: the array of values passed to FooBarConverter contains DependencyProperty.UnsetValue
for each value (two in this case). Removing converters on child bindings (FooConverter and BarConverter) gives me the actual values. BTW: These converters are properly called, it looks like their result is being discarded.
Is this the intended behavior? I want to bind 2 properties, I need to convert at least one of them before throwing them in MultiValueConverter
...
a source to share
The developers on the overall Kishore team have come to the conclusion that in order to create such a MultiBinding, child Bindings must return the same result type as the parent MultiBinding. So, in my case, if I wanted the parent MultiBinding to return a value of type Visibility, the child bindings must also return visibility values. This will not cause UnsetValues to pass your converter method, which will give you unwanted results.
Here is a piece of code that works for me. Note that the "VisibleIfTrue" and "EnumToVisibility" converters are both Visible return types:
<Grid.Visibility>
<MultiBinding Converter="{StaticResource MultiVisibilityConverter}">
<Binding Path="JobHasData" Converter="{StaticResource VisibleIfTrue}" />
<Binding Path="CurrentMode" Converter="{StaticResource EnumToVisibility}" ConverterParameter="{x:Static Mode.Setup}" />
</MultiBinding>
</Grid.Visibility>
It's a shame that you cannot pass different types of values to it for processing and give the desired result. (I first tried to pass bools to the converter.)
Hope this helps anyone who has been waiting seven years for a response.;)
a source to share
you mentioned converter in Multibinding tag like this
<TextBlock Grid.Row="3" Grid.Column="1" Padding="5">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource sumConverter}">
<Binding Path="FirstNum" />
<Binding Path="SecondNum" />
<Binding Path="ThirdNum" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
a source to share
If WPF was before 4.0 then this is a known and fixed bug that has a workaround.
Here was an example implementation of a workaround for a poor person who is forced to work with older versions.
In short, older versions of wpf try to convert values from multi-linked child bindings that have converters directly in the target property property. The workaround is to create a hidden label, move the multi-binding or its child binding converter to label.content as it expects an object and then bind the desired property to it.
a source to share