Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ComboBox selection: interaction between SelectedItem and SelectedIndex

$
0
0

I have a ComboBox that is bound to a list of items, and initially the first item in the list is selected:

<ComboBox ItemsSource="{StaticResource items}"
          SelectedIndex="0" 
          IsEditable="False" />

This works fine.

I want to use the selection from the ComboBox to set a property on a CLR object. I thought to accomplish this with a OneWayToSource binding:

<ComboBox ItemsSource="{StaticResource items}"
          SelectedIndex="0" 
          SelectedItem="{Binding Mode=OneWayToSource,
                                 Source={StaticResource clr_object},
                                 Path=selected_item}"
          IsEditable="False" />

However when I do this, the ComboBox starts with no selection .. in other words, the effect of SelectedIndex="0" is inhibited. Is this expected behavior? I was hoping that the OneWayToSource binding would not interfere with item selection.

Thanks for any assistance or clarification,

Mark Z.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>