-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeViewItemBase.cs
92 lines (85 loc) · 3.73 KB
/
TreeViewItemBase.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.ComponentModel;
namespace RegFineViewer
{
// ----------------------------------------------------------
// Cette classe de base provient du tutoriel WPF-TUTORIAL;COM
// Les objets qui heritent de cette classe de base bénéficie de deux propriétés:
// isSelected et isExpanded
// qui permettent de d'accéder à ces attributs de la TreeView depuis le code-behind
// (Ce que le WPF ne permet pas de façon native)
// ----------------------------------------------------------
public class TreeViewItemBase : INotifyPropertyChanged
{
// ----------------------------------------------------------
// Propriété isSelected et IsSelected
// ----------------------------------------------------------
private bool isSelected;
public bool IsSelected
{
// ------------------------------------------------------
// Get: on stocke dana la variable privée
// ------------------------------------------------------
get
{
return this.isSelected;
}
// ------------------------------------------------------
// Set: si changement, on notifie le TreeViewItem
// ------------------------------------------------------
set
{
if (value != this.isSelected)
{
this.isSelected = value;
NotifyPropertyChanged("IsSelected");
}
}
}
// ----------------------------------------------------------
// Propriété isExpanded et IsExpanded
// ----------------------------------------------------------
private bool isExpanded;
public bool IsExpanded
{
// ------------------------------------------------------
// Get: on stocke dana la variable privée
// ------------------------------------------------------
get { return this.isExpanded; }
// ------------------------------------------------------
// Set: si changement, on notifie le TreeViewItem
// ------------------------------------------------------
set
{
if (value != this.isExpanded)
{
this.isExpanded = value;
NotifyPropertyChanged("IsExpanded");
}
}
}
// ----------------------------------------------------------
// fonction héritée de INotifyPropertyChanged
// ----------------------------------------------------------
public event PropertyChangedEventHandler PropertyChanged;
// ----------------------------------------------------------
// Notification
// ----------------------------------------------------------
public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
}
// -------------------------------------------------------------
// Necessite aussi la section suivante dans le XAML <TreeView>
// -------------------------------------------------------------
// <TreeView.ItemContainerStyle>
// <Style TargetType = "TreeViewItem" >
// <Setter Property= "IsSelected" Value="{Binding IsSelected}" />
// <Setter Property= "IsExpanded" Value="{Binding IsExpanded}" />
// </Style>
// </TreeView.ItemContainerStyle>
// -------------------------------------------------------------
// Malheureusement non-compatible avec la library MaterialDesign
// -------------------------------------------------------------