1+ using System . Collections . ObjectModel ;
2+ using Avalonia . Controls ;
3+ using Avalonia . Controls . Models . TreeDataGrid ;
4+ using CommunityToolkit . Mvvm . ComponentModel ;
5+
6+ namespace SampleApp . ViewModels ;
7+
8+ public class Person
9+ {
10+ public string ? FirstName { get ; set ; }
11+ public string ? LastName { get ; set ; }
12+ public int Age { get ; set ; }
13+ public ObservableCollection < Person > Children { get ; } = new ( ) ;
14+ }
15+
16+ public class TreeDataGridViewModel : ObservableObject
17+ {
18+ private readonly ObservableCollection < Person > _people = new ( )
19+ {
20+ new Person
21+ {
22+ FirstName = "Eleanor" ,
23+ LastName = "Pope" ,
24+ Age = 32 ,
25+ Children =
26+ {
27+ new Person { FirstName = "Marcel" , LastName = "Gutierrez" , Age = 4 }
28+ }
29+ } ,
30+ new Person
31+ {
32+ FirstName = "Jeremy" ,
33+ LastName = "Navarro" ,
34+ Age = 74 ,
35+ Children =
36+ {
37+ new Person
38+ {
39+ FirstName = "Jane" ,
40+ LastName = "Navarro" ,
41+ Age = 42 ,
42+ Children =
43+ {
44+ new Person { FirstName = "Lailah " , LastName = "Velazquez" , Age = 16 }
45+ }
46+ }
47+ }
48+ } ,
49+ new Person { FirstName = "Jazmine" , LastName = "Schroeder" , Age = 52 }
50+ } ;
51+
52+ public TreeDataGridViewModel ( )
53+ {
54+ Source = new HierarchicalTreeDataGridSource < Person > ( _people )
55+ {
56+ Columns =
57+ {
58+ new HierarchicalExpanderColumn < Person > (
59+ new TextColumn < Person , string > ( "First Name" , x => x . FirstName ) ,
60+ x => x . Children ) ,
61+ new TextColumn < Person , string > ( "Last Name" , x => x . LastName ) ,
62+ new TextColumn < Person , int > ( "Age" , x => x . Age )
63+ }
64+ } ;
65+ }
66+
67+ public HierarchicalTreeDataGridSource < Person > Source { get ; }
68+ }
0 commit comments