Re-sort WPF DataGrid after bounded Data has changed

前端 未结 5 2142
眼角桃花
眼角桃花 2020-12-14 06:43

I am looking for a way to re-sort my DataGrid when the underlying data has changed.

(The setting is quite standard: Th

5条回答
  •  萌比男神i
    2020-12-14 07:36

    This is more for clarification than it is an answer, but WPF always binds to an ICollectionView and not the source collection. CollectionViewSource is just a mechanism used to create/retrieve the collection view.

    Here's a great resource about the topic which should help you make better use of collection views in WPF: http://bea.stollnitz.com/blog/?p=387

    Using CollectionViewSource in XAML can actually simplify your code some:

    
        
          
            
          
        
    
    
    ...
    
    
    
    

    Some people argue that when following the MVVM pattern, the view model should always expose the collection view but in my opinion, it just depends on the use case. If the view model is never going to directly interact with the collection view, it's just easier to configure it in XAML.

提交回复
热议问题