简体   繁体   中英

ListView Grouping WPF - show only groups with multiple items

Let's say I group ObservableCollection by column "time". How can I display only groups with multiple items?

This is a bit crude, but you can collapse the groups you don't want:

<ListBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style TargetType="GroupItem">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ItemCount}" Value="1">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListBox.GroupStyle>

It's somewhat frustrating to work with this, because of the poor quality of the WPF documentation. GroupStyle.HeaderTemplate is documented better than most of WPF, but they still, preposterously, can't be bothered to tell you what type the DataContext for the template is or what its properties are. Well, it's MS.Internal.Data.CollectionViewGroupInternal .

If the above doesn't apply to what you're doing, that's what you get for writing vague one-line questions with no detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM