Sunday, August 19, 2012 12:00 AM
Suppose I have an in-memory collection of sports players including the college they attended, position they play, and current team, bound to 3 different controls (ListBoxes) in order to browse different players by those 3 different groupings
Is it possible to synchronize the 3 controls with different ICollectionViews so that a selection in one is synchronized with the others? Or is this only possible if they are all bound to the same ICollectionView instance? I have the 3 ListBoxes already set IsSynchronizedWithCurrentItem="true" but I suspect this only works if they're using the same ICollectionView?
This is what I'm doing in my code:
ICollectionView collegeView = new ListCollectionView(playerDatabase); collegeView.GroupDescriptions.Add(new PropertyGroupDescription("CollegeName")); collegeView.SortDescriptions.Add(new SortDescription("CollegeName", ListSortDirection.Ascending)); collegeView.SortDescriptions.Add(new SortDescription("FirstName", ListSortDirection.Ascending)); lstCollege.ItemsSource = collegeView; ICollectionView positionView = new ListCollectionView(playerDatabase); positionView.GroupDescriptions.Add(new PropertyGroupDescription("PositionCode", new NFLPositionGrouper())); positionView.SortDescriptions.Add(new SortDescription("PositionName", ListSortDirection.Ascending)); positionView.SortDescriptions.Add(new SortDescription("FirstName", ListSortDirection.Ascending));
The playerDatabase variable is coming from a LINQ to Entity query projecting an anonymous type
Monday, August 20, 2012 9:38 PMModerator
Even though you are using different ListCollectionViews, I don't see any reason why you can't still bind all the SelectedItems from the listboxes together, to the same two-way property.
I thought it was a reasonable excuse to knock up an example that others may also find useful, so I've uploaded a project to MSDN Samples, for you to download and try:
Note: It's basic and rough as hell, so don't judge it an any other way than simply to get the concept over.
- Edited by XAML guyMicrosoft Community Contributor, Moderator Monday, August 20, 2012 9:41 PM tweaks
- Marked As Answer by Annabella LuoModerator Tuesday, August 28, 2012 10:31 AM