@@ -17,15 +17,6 @@ namespace SourceGit.Views
17
17
{
18
18
public class BranchTreeNodeIcon : UserControl
19
19
{
20
- public static readonly StyledProperty < ViewModels . BranchTreeNode > NodeProperty =
21
- AvaloniaProperty . Register < BranchTreeNodeIcon , ViewModels . BranchTreeNode > ( nameof ( Node ) ) ;
22
-
23
- public ViewModels . BranchTreeNode Node
24
- {
25
- get => GetValue ( NodeProperty ) ;
26
- set => SetValue ( NodeProperty , value ) ;
27
- }
28
-
29
20
public static readonly StyledProperty < bool > IsExpandedProperty =
30
21
AvaloniaProperty . Register < BranchTreeNodeIcon , bool > ( nameof ( IsExpanded ) ) ;
31
22
@@ -35,16 +26,23 @@ public bool IsExpanded
35
26
set => SetValue ( IsExpandedProperty , value ) ;
36
27
}
37
28
38
- static BranchTreeNodeIcon ( )
29
+ protected override void OnDataContextChanged ( EventArgs e )
30
+ {
31
+ base . OnDataContextChanged ( e ) ;
32
+ UpdateContent ( ) ;
33
+ }
34
+
35
+ protected override void OnPropertyChanged ( AvaloniaPropertyChangedEventArgs change )
39
36
{
40
- NodeProperty . Changed . AddClassHandler < BranchTreeNodeIcon > ( ( icon , _ ) => icon . UpdateContent ( ) ) ;
41
- IsExpandedProperty . Changed . AddClassHandler < BranchTreeNodeIcon > ( ( icon , _ ) => icon . UpdateContent ( ) ) ;
37
+ base . OnPropertyChanged ( change ) ;
38
+
39
+ if ( change . Property == IsExpandedProperty )
40
+ UpdateContent ( ) ;
42
41
}
43
42
44
43
private void UpdateContent ( )
45
44
{
46
- var node = Node ;
47
- if ( node == null )
45
+ if ( DataContext is not ViewModels . BranchTreeNode node )
48
46
{
49
47
Content = null ;
50
48
return ;
0 commit comments