MultipleBinding for a WPF Converter… when does ConvertBack get called?
-
28-06-2021 - |
Question
I have a ComboBox with a set of values. The selected value is determined by a Converter with a multiple two-way binding. When the user changes the value in the ComboBox, I expected the ConvertBack method to get called and change the values of the two properties used in the Multiple Binding, but this doesn't happen, even when the ComboBox loses focus. I tried to change the UpdateSourceTrigger property to "LosesFocus" but this is apparently not valid for a MultipleBinding. How do I get the ConvertBack method to fire, either when the value changes or when the control loses focus? Either will work for my purposes.
XAML:
<ComboBox ItemsSource="{Binding DescriptionList}" DisplayMemberPath="Description" SelectedValuePath="Description" IsEnabled="{Binding EditMode}">
<ComboBox.SelectedValue>
<MultiBinding Converter="{StaticResource DescriptionConverter}">
<Binding Path="PersonRow.DescriptionType" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="PersonRow.DescriptionSuccessful" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</ComboBox.SelectedValue>
</ComboBox>
Solution
You probably need to add Mode="TwoWay"
to your <MultiBinding>
.
OTHER TIPS
Jay's suggestion hinted me in the right direction. I also added an UpdateSourceTrigger="LostFocus" to the MultiBinding tag and was able to fire the event.