WPF ComboBox SelectedItem - change to previous value

前端 未结 4 1045
Happy的楠姐
Happy的楠姐 2020-12-30 00:13

I have a ComboBox that has the SelectedItem bound to the ViewModel.



        
4条回答
  •  北海茫月
    2020-12-30 01:04

    Another way to do it (make sure you also read the comments):

    http://amazedsaint.blogspot.com/2008/06/wpf-combo-box-cancelling-selection.html

    From the link: Another solution for issue of recursive calling of event handler without global variable is to cancel handler assignment before programmatic selection change, and reassign it after that.

    Ex:

    cmb.SelectionChanged -= ComboBox_SelectionChanged;
    cmb.SelectedValue = oldSel.Key;
    cmb.SelectionChanged += ComboBox_SelectionChanged;
    

提交回复
热议问题