WPF MVVM ComboBox SelectedItem or SelectedValue not working

前端 未结 18 2215
一生所求
一生所求 2020-12-05 06:22

Update

After a bit of investigating. What seems to be the issue is that the SelectedValue/SelectedItem is occurring before the Item source is finis

相关标签:
18条回答
  • 2020-12-05 06:52

    ComboBox.SelectionBoxItem.ToString()

    0 讨论(0)
  • 2020-12-05 06:53

    Have you tried implementing INotifyPropertyChanged in your viewmodel, and then raise the PropertyChanged event when the SelectedItem gets set?

    If this in itself doesn't fix it, then you will be able to manually raise the PropertyChanged event yourself when navigating back to the page, and that should be enough to get WPF to redraw itself and show the correct selected item.

    0 讨论(0)
  • 2020-12-05 06:53

    I have noticed this behavior before as well. I have noticed that the SelectedIndex property doesn't cause the same bug. If you can restructure your ViewModel to expose the index of the selected item, and bind to that, you should be good to go.

    0 讨论(0)
  • 2020-12-05 06:55

    IsSyncronizedWithCurrent=False will make it work.

    0 讨论(0)
  • 2020-12-05 06:57

    Setting IsSynchronizedWithCurrentItem="True" worked for me!

    0 讨论(0)
  • 2020-12-05 06:57

    The type of the SelectedValuePath and the SelectedValue must be EXACTLY the same.

    If for example the type of SelectedValuePath is Int16 and the type of the property that binds to SelectedValue is int it will not work.

    I spend hours to find that, and that's why I am answering here after so much time the question was asked. Maybe another poor guy like me with the same problem can see it.

    0 讨论(0)
提交回复
热议问题