diff --git a/src/Views/BranchTree.axaml b/src/Views/BranchTree.axaml index a90b327e..dad4f820 100644 --- a/src/Views/BranchTree.axaml +++ b/src/Views/BranchTree.axaml @@ -55,9 +55,7 @@ DoubleTapped="OnDoubleTappedBranchNode"> - + NodeProperty = - AvaloniaProperty.Register(nameof(Node)); - - public ViewModels.BranchTreeNode Node - { - get => GetValue(NodeProperty); - set => SetValue(NodeProperty, value); - } - public static readonly StyledProperty IsExpandedProperty = AvaloniaProperty.Register(nameof(IsExpanded)); @@ -35,16 +26,23 @@ namespace SourceGit.Views set => SetValue(IsExpandedProperty, value); } - static BranchTreeNodeIcon() + protected override void OnDataContextChanged(EventArgs e) { - NodeProperty.Changed.AddClassHandler((icon, _) => icon.UpdateContent()); - IsExpandedProperty.Changed.AddClassHandler((icon, _) => icon.UpdateContent()); + base.OnDataContextChanged(e); + UpdateContent(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsExpandedProperty) + UpdateContent(); } private void UpdateContent() { - var node = Node; - if (node == null) + if (DataContext is not ViewModels.BranchTreeNode node) { Content = null; return;