How do you handle a ComboBox SelectionChanged in MVVM?

前端 未结 3 1983
南旧
南旧 2020-12-13 06:45

For those doing pure MVVM, how do you handle a ComboBox SelectionChanged event without reverting to code behind?

I tried e.g. AttachedBehaviors but Event=\"SelectedC

3条回答
  •  醉话见心
    2020-12-13 07:18

    I'm not sure if what you're after is possible, but the way I do it is to simply bind the SelectedItem to a property on view model. Then within the property setter, I call any custom code that I want to happen i.e. setting other properties based on rule. If I need the selected item to be bound to an object aswell (for other bound controls to update) I set this in the setter too and send out a notification.

提交回复
热议问题