1

I have a View that contains a Combobox. The Combobox SelectedItem property is data bound to SelectedX property of View Model as two way data binding. When the viewModel is initialized, the SelectedX property is set correctly. But after that when the view renders, it resets the value of SelectedX(since the binding is two-way). So the two way data binding for the Combobox is basically not working. Please advise.

This is the xaml for my view. I initialize the View model first with apprpriate values for Relationships and SelectedX. When the view renders, the combo box resets the value for SelectedX. (I figured that by adding breakpoints). Hope this helps

   <ComboBox Grid.Row="1" Grid.Column="1" Margin="5" Background="White"     BorderBrush="DarkGray"
              SelectedItem="{Binding SelectedX, Mode=TwoWay}" 
              ItemsSource="{Binding Relationships}" DisplayMemberPath="Value" 
              SelectedValuePath="Value" SelectedValue="{Binding Key, Mode=TwoWay}"
              IsEditable="False" IsReadOnly="True" />
ankhuri
  • 179
  • 11

1 Answers1

1
SelectedValue="{Binding Key, Mode=TwoWay}"

This will change the SelectedItem to its SelectedValue.

Sankarann
  • 2,625
  • 4
  • 22
  • 59
  • Thanks Sankarann, not adding SelectedValue property solves my rpoblem. You are correct in mentioning that adding this resets the SelectedItem. – ankhuri Jan 20 '14 at 06:58