WPF Sorting an ObservableCollection de-selects a ComboBox

前端 未结 2 1527
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 12:43

I have a ComboBox where a user can select what JobType they are working on. The ComboBox has a list of AllJobTypes. The problem stems from when a user adds a new JobType,

2条回答
  •  天命终不由人
    2020-12-22 13:33

    Instead of sorting the collection in the view model, you should bind the ComboBox's ItemsSource to a CollectionViewSource, where you can specify a SortDescription:

    
        
            
                
                    
                
            
        
    
        ...
        
        ...
    
    
    

    For further information see How to: Sort and Group Data Using a View in XAML

提交回复
热议问题