forked from tloten/bulk-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeViewModel .cs
47 lines (37 loc) · 1.24 KB
/
TreeViewModel .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
44
45
46
47
using System.Collections.Generic;
using System.ComponentModel;
namespace BulkQuery
{
internal class TreeViewModel<T> : INotifyPropertyChanged
{
public string Name { get; private set; }
public List<TreeViewModel<T>> Children { get; }
public T Value { get; private set; }
private bool? isChecked = false;
public bool? IsChecked
{
get { return isChecked; }
set { SetIsChecked(value, true); }
}
public TreeViewModel(string name, T value)
{
Name = name;
Children = new List<TreeViewModel<T>>();
Value = value;
}
private void SetIsChecked(bool? value, bool updateChildren)
{
if (value == isChecked)
return;
isChecked = value;
if (updateChildren && isChecked.HasValue)
Children.ForEach(c => c.SetIsChecked(isChecked, true));
NotifyPropertyChanged("IsChecked");
}
private void NotifyPropertyChanged(string info)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}