6

I've set up a CompositeCollection containing two or more collections as follows (simplified):

<Grid.Resources>
    <CollectionViewSource x:Key="CollectionA" Source="{Binding CollectionA}" />
    <CollectionViewSource x:Key="CollectionB" Source="{Binding CollectionB}" />
    <CompositeCollection x:Key="FullCollection">
        <CollectionContainer Collection="{Binding Source={StaticResource CollectionA}}" />
        <CollectionContainer Collection="{Binding Source={StaticResource CollectionB}}" />
    </CompositeCollection>
</Grid.Resources>

...

<ListView ItemsSource="{StaticResource FullCollection}">
    <ListView.View>
        <GridView>

And then some columns displayed inside the GridView. However, I can't seem to be able to add GroupDescriptions to the CompositeCollection, only the individual CollectionViewSource elements.

What I want to do is group by the collections themselves, such that the ListView has a header, then the first collection's contents, another header, then the second collection's contents, etc.

Am I barking up the wrong tree trying to group these in this way?

Dan
  • 1,130
  • 2
  • 20
  • 38

1 Answers1

-1

I had the same problem but for a drop down combobox. The solution was to simply had some disabled items inbetween the collections, e.g. adapting to your problem it would be something like:

<Grid.Resources>
    <CollectionViewSource x:Key="CollectionA" Source="{Binding CollectionA}" />
    <CollectionViewSource x:Key="CollectionB" Source="{Binding CollectionB}" />
    <CompositeCollection x:Key="FullCollection">
        <ListViewItem IsEnabled="False">Collection A:</ListViewItem>
        <CollectionContainer Collection="{Binding Source={StaticResource CollectionA}}" />
        <ListViewItem IsEnabled="False">Collection B:</ListViewItem>
        <CollectionContainer Collection="{Binding Source={StaticResource CollectionB}}" />
    </CompositeCollection>
</Grid.Resources>
geometrikal
  • 3,195
  • 2
  • 29
  • 40