-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.axaml.cs
43 lines (37 loc) · 1.37 KB
/
MainWindow.axaml.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
41
42
43
using Avalonia.Collections;
using Avalonia.Controls;
using DynamicData;
using DynamicData.Binding;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Subjects;
namespace DataGridDebug
{
internal record Row(int Value, string Group);
public partial class MainWindow : Window
{
private readonly BehaviorSubject<Func<Row, bool>> _filter = new(_ => true);
public MainWindow()
{
InitializeComponent();
ObservableCollection<Row> rows = new(Enumerable.Range(1, 50).Select(v => new Row(v, "Group")));
rows
.ToObservableChangeSet()
.Filter(_filter)
.Bind(out ReadOnlyObservableCollection<Row> filteredRows)
.Subscribe();
var groupedSource = new DataGridCollectionView(filteredRows, true, true);
DataGridPathGroupDescription group = new("Group");
groupedSource.GroupDescriptions.Add(group);
TestDataGrid.ItemsSource = groupedSource;
}
private void Button_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (int.TryParse(TestTextBox.Text ?? string.Empty, out var count))
{
_filter.OnNext(r => r.Value <= count);
}
}
}
}