Setting ComboBox.SelectedIndex Breaks OneWayToSource Binding On ComboBox.SelectedItem
The data template displays the following:
<ComboBox IsSynchronizedWithCurrentItem="False"
SelectedIndex="0"
SelectedItem="{Binding Path=Value, Mode=OneWayToSource}"
ItemsSource="{Binding Path=EnumeratedValues, Mode=OneTime}"/>
When installed SelectedIndex
(as shown above), binding OneWayToSource
to Value
does not work. If I don't install SelectedIndex
, the binding to is Value
fine.
However, I would really like to set it SelectedIndex
to 0, because if I omit setting it, there is ComboBox
no item selected by default.
Can anyone see a way that I can maintain binding to Value
, and at the same time ensure that the first item in is ComboBox
selected by default?
source to share
Why not have two-way binding and just set the property value of your object in code?
Edit: Added explanation: This allows you to just work with your business object. The point of using data binding is to decouple your business objects from the user interface and just manipulate your business object and render that interface.
source to share