quentinA
asked on
How can I filter the ItemSources of two ListBoxes that have a common CollectionViewSource
Hi,
I have a WPF MainWindow that has a CollectionViewSource in the Window.Resources section.
In the main layout grid I have two ListBox controls.
I would like to use a filtered version of the CollectionViewSource for each listbox, so that they each show different ListItems from the common source.
Is there any way I can do this?
Preferrably by using a property (or attached property) in xaml on each ListBox as a way of determining the filter.
I have a WPF MainWindow that has a CollectionViewSource in the Window.Resources section.
In the main layout grid I have two ListBox controls.
I would like to use a filtered version of the CollectionViewSource for each listbox, so that they each show different ListItems from the common source.
Is there any way I can do this?
Preferrably by using a property (or attached property) in xaml on each ListBox as a way of determining the filter.
I don't quite understand what you are working with, and what you are asking for...
ASKER
I have a list of Asterix the Gaul characters with their hair color:
public MainWindowViewModel()
{
this.AsterixCharacters = new ObservableCollection<Aster ixCharacte r>();
this.AsterixCharacters.Add (new AsterixCharacter("Asterix" , HairColor.Blond));
this.AsterixCharacters.Add (new AsterixCharacter("Assuranc etourix", HairColor.Blond));
this.AsterixCharacters.Add (new AsterixCharacter("Maestria ", HairColor.Blond));
this.AsterixCharacters.Add (new AsterixCharacter("Idefix", HairColor.White));
this.AsterixCharacters.Add (new AsterixCharacter("Goudurix ", HairColor.Blond));
this.AsterixCharacters.Add (new AsterixCharacter("Mme Agecanonix", HairColor.Red));
this.AsterixCharacters.Add (new AsterixCharacter("Gueusela mbix", HairColor.Blond));
this.AsterixCharacters.Add (new AsterixCharacter("Panorami x", HairColor.White));
this.AsterixCharacters.Add (new AsterixCharacter("Pepe", HairColor.Black));
this.AsterixCharacters.Add (new AsterixCharacter("Obelix", HairColor.Red));
this.AsterixCharacters.Add (new AsterixCharacter("Abraraco urcix", HairColor.Red));
}
public ObservableCollection<Aster ixCharacte r> AsterixCharacters;
.......................... .......... .......... .......
the MainWindow is set up to use the collection above for its <CollectionViewSource>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
asterixCharacters = new ObservableCollection<Aster ixCharacte r>(new MainWindowViewModel().Aste rixCharact ers);
cvs = (CollectionViewSource)(thi s.FindReso urce("cvs" ));
cvs.Source = asterixCharacters;
view = (ListCollectionView)Collec tionViewSo urce.GetDe faultView( cvs);
}
.......................... .......... .......... ..
the MainWindow has 2 listboxes:
<Window.Resources>
<CollectionViewSource x:Key="cvs"/>
</Window.Resources>
<Grid>
<ListBox />
<ListBox/>
</Grid>
.......................... .......... .......... .......
I would like to have a property on each ListBox, that can be assigned in XAML, that causes one listbox to show those Asterix characters with blond hair; and the second listbox to show those characters with red hair.
Ultimately, i'm trying to understand this in order to make a custom control out of a listbox a few buttons and a combobox.
.......................... .......... .......... .......... ....
public MainWindowViewModel()
{
this.AsterixCharacters = new ObservableCollection<Aster
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
this.AsterixCharacters.Add
}
public ObservableCollection<Aster
..........................
the MainWindow is set up to use the collection above for its <CollectionViewSource>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
asterixCharacters = new ObservableCollection<Aster
cvs = (CollectionViewSource)(thi
cvs.Source = asterixCharacters;
view = (ListCollectionView)Collec
}
..........................
the MainWindow has 2 listboxes:
<Window.Resources>
<CollectionViewSource x:Key="cvs"/>
</Window.Resources>
<Grid>
<ListBox />
<ListBox/>
</Grid>
..........................
I would like to have a property on each ListBox, that can be assigned in XAML, that causes one listbox to show those Asterix characters with blond hair; and the second listbox to show those characters with red hair.
Ultimately, i'm trying to understand this in order to make a custom control out of a listbox a few buttons and a combobox.
..........................
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.