/
CountriesPageViewModel.cs
40 lines (34 loc) · 1.49 KB
/
CountriesPageViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Controls.Selection;
using ProControlsDemo.Models;
namespace ProControlsDemo.ViewModels
{
internal class CountriesPageViewModel
{
private ObservableCollection<Country> _data;
public CountriesPageViewModel()
{
_data = new ObservableCollection<Country>(Countries.All);
Source = new FlatTreeDataGridSource<Country>(_data)
{
Columns =
{
new TextColumn<Country, string>("Country", x => x.Name, (r, v) => r.Name = v, new GridLength(6, GridUnitType.Star)),
new TextColumn<Country, string>("Region", x => x.Region, new GridLength(4, GridUnitType.Star)),
new TextColumn<Country, int>("Population", x => x.Population, new GridLength(3, GridUnitType.Star)),
new TextColumn<Country, int>("Area", x => x.Area, new GridLength(3, GridUnitType.Star)),
new TextColumn<Country, int>("GDP", x => x.GDP, new GridLength(3, GridUnitType.Star)),
}
};
Selection = new SelectionModel<IRow>(Source.Rows)
{
SingleSelect = false,
};
}
public FlatTreeDataGridSource<Country> Source { get; }
public SelectionModel<IRow> Selection { get; }
public void AddCountry(Country country) => _data.Add(country);
}
}