Grouping data in a WPF tree

I want to create WPF TreeViewwith two grouping options (radio buttons). Thus, the data will be grouped differently in a two-level hierarchy, with the lowest level being the actual data elements, and groups are just a way of presenting the data for easier understanding.

They will also be able to select elements by groups (checkboxes), but I realized that this part has already been calculated, for example. if I want to represent database objects and want them to be grouped either by scheme or by type of object (table, view, function, etc.).

I just don’t know how I can start working in two grouping modes. Should I completely restructure my ObservableCollectionwhenever grouping mode changes or is there an easier way?

Besides, what if mine DataTemplatefor the second level will be slightly different depending on the grouping mode, for example, if you are grouped by type of object, you need to display the scheme at level 2?

Can someone give me some tips on how to get started and what methods to use?

+5
source share
2 answers

, GroupDescriptions CollectionViewSource. , - :

CollectionViewSource.GetDefaultView(yourCollection).GroupDescriptions.Add(
    new PropertyGroupDescription("PropertyName"));

XAML, CollectionViewSource .

    <CollectionViewSource
        Source="{StaticResource yourCollection}"
        xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework">
        <CollectionViewSource.GroupDescriptions>
            <dat:PropertyGroupDescription PropertyName="PropertyName"/>
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

ItemsControl, ListBox, GroupStyle. TreeView, , Groups ICollectionView. Bea Stollnitz :

+3

HierarchicalDataTemplate. .

0

All Articles