For some reason, the IMultiValueConverter
is not setting my property through ConvertBack
function.
My custom ComboBox
XAML
looks like this:
<ComboBox.SelectedIndex>
<MultiBinding Converter="{StaticResource IDToIndex}" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnTargetUpdated="True">
<Binding Path="SelectedID" ElementName="InnerComboBoxName"/>
<Binding Path="ItemsSource" ElementName="InnerComboBoxName"/>
</MultiBinding>
</ComboBox.SelectedIndex>
and the IMultiValueConverter
like this:
public class IndexIDConverter : System.Windows.Data.IMultiValueConverter
{
private IDDisplayList tmp = new IDDisplayList();
public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture )
{
if ( values[0] == DependencyProperty.UnsetValue )
values[0] = -1;
if ( values[1] == DependencyProperty.UnsetValue )
values[1] = new IDDisplayList();
int? ajdi = (int?) values[0];
IDDisplayList lista = (IDDisplayList) values[1];
tmp = lista;
int? index = lista?.IndexOf( lista?.Where( x => x.ID == ajdi )?.FirstOrDefault() );
return index == null ? -1 : index;
}
public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture )
{
if ( value == DependencyProperty.UnsetValue )
value = -1;
int index = (int)value;
int? id = tmp[index].ID;
return new object[] { id, tmp };
}
}
Here is my Binding
inside of a Page
:
<V3:ComboBox ItemsSource="{Binding Source={x:Static s:CachedData.Areas}}"
SelectedID="{Binding AreaID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnTargetUpdated=True}"/>
Everything is working fine. Converter is being called upon opening the Page
, the SelectedIndex
property is being set correctly, and when I pick something from the ComboBox
, the ConvertBack
is being called. Now, I have the values in my id
and tmp
properties just the way I need them to be, but the SelectedID
property of the ComboBox
stays the same. Does anyone sees the issue here?