WPF CompositeCollection grouping by each collection view
Asked Answered
D

1

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?

Duty answered 6/12, 2017 at 11:21 Comment(1)
Nobody? Dan did you find any workaround?Pester
F
-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>
Finkelstein answered 18/2, 2020 at 2:35 Comment(3)
You can't grouping dynamic collections.Modulator
@JokeHuang it worked for me, what do you mean?Finkelstein
Your group name is static, can not change at the run time, and can not group by different properties at the run time.Modulator

© 2022 - 2024 — McMap. All rights reserved.