I am creating an application using the MVVM pattern and somewhere I have a view which contains a ComboBox.
<Controls:SettingsComboBox x:Name="Setting"
SelectedIndex="{Binding SteeringIndex, Mode=TwoWay}"
IsEnabled="{Binding SteerAttached, Mode=TwoWay}">
<ComboBoxItem Content="{Binding Path=on, Source={x:Static Localization:CultureResources.ObjectDataProvider}}"/>
<ComboBoxItem Content="{Binding Path=off, Source={x:Static Localization:CultureResources.ObjectDataProvider}}"/>
</Controls:SettingsComboBox>
So the SelectedIndex
and IsEnabled
are bound to the view model which retrieves the values from a settings file or gets it from an external event.
If SelectedIndex
is 0 (on) and IsEnabled
is set to false, everything is OK. If SelectedIndex
is 1 (off) and IsEnabled
is set to false the SelectedIndex
is somehow set to -1, thus resulting in an empty combo box.
Why does this happen and how can I work around it? I can set the SelectedIndex
back when I receive the event to change the IsEnabled
property, but that still leaves and empty combobox when it's disabled so that doesn't really qualify as a solution.