How to preserve TwoWay binding of CurrentItem when databinding to CollectionViewSource in ComboBox

前端 未结 4 1833
粉色の甜心
粉色の甜心 2021-01-04 03:07

Lets say we got a simple VM class

public class PersonViewModel : Observable
    {
        private Person m_Person= new Person(\"Mike\", \"Smith\");

                 


        
4条回答
  •  萌比男神i
    2021-01-04 03:48

    The TwoWay binding works as it should, but ComboBox doesn't update itself on the UI when you set SelectedItem or SelectedIndex from code. If you want this functionality, just extend ComboBox and listen to SelectionChanged inherited from Selector or if you only want to set an initial selection, do it on Loaded.

提交回复
热议问题