Best practice for displaying the same collection in multiple datagrid controls
I have a situation where I need to create a tab control, with a datagrid on each tab. I am using an observable collection and for an example the items in the collection are of either group A, B, C. One tab/datagrid would display items from group A, and subsequent tab/datagrids would display groups B & C respectively. Any edits to any of the 3 datagrids would have to be ultimately captured in the observable collection.
My question is what is the best approach to accomplish this? I am relatively new to WPF and my first approach was to create a user control datagrid since each datagrid will have the same columns and business logic. Is there another way to define a datagrid column definitions and apply that to each datagrid?
Additionally, would I create a ViewModel for each datagrid? Any high level guidance would be helpful.
I suggest you use CollectionViewSource class. It will allow you to create different views to use as data sources for different grids. But all those views will propagate changes to one underlying Observable Collection. This is a very good article explaining how to work with CollectionViewSource: http://blogs.msdn.com/b/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx
链接地址: http://www.djcxy.com/p/64736.html上一篇: 在WPF画布中保持孩子的相对位置