dimanche 28 juin 2015

WPF TreeView Group By

I have class "Person" that look like this:

public class Person
{
        public string Name { get; set; }
        public int Age { get; set; }
        public string Country{ get; set; }
        public List<Person> Children { get; set; }
}

I want to create a TreeView in WPF that will present the Persons by Country.

For example:

  • New york
    • Bob
      • New York
        • Ethan
        • Owen
      • Canada
        • Benjamin
        • James
    • Kevin
      • Paris
        • Louis
    • William
  • Finland
    • Oliver
      • Hungary
        • Ben
        • Paul
      • Iceland
        • Arthur
          • Benjamin
      • England
        • Gabriel
        • Victor
    • Eino
      • Paris
        • Gabriel
        • Adam
    • Emma

My TreeView :

 <TreeView.Resources>
  <HierarchicalDataTemplate ItemsSource="{Binding People}" DataType="{x:Type Person}">
       <Label Content="{Binding Name}"></Label>
   </HierarchicalDataTemplate>

Is there someway to use "Group by" in tree view?

Aucun commentaire:

Enregistrer un commentaire