Skip to content

Commit 1f0ab2b

Browse files
committed
refactor: simpfy SourceGit.Views.BranchTreeNodeIcon
Signed-off-by: leo <[email protected]>
1 parent fd93525 commit 1f0ab2b

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/Views/BranchTree.axaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
DoubleTapped="OnDoubleTappedBranchNode">
5656

5757
<!-- Icon -->
58-
<v:BranchTreeNodeIcon Grid.Column="0"
59-
Node="{Binding}"
60-
IsExpanded="{Binding IsExpanded}"/>
58+
<v:BranchTreeNodeIcon Grid.Column="0" IsExpanded="{Binding IsExpanded}"/>
6159

6260
<!-- Name -->
6361
<TextBlock Grid.Column="1"

src/Views/BranchTree.axaml.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ namespace SourceGit.Views
1717
{
1818
public class BranchTreeNodeIcon : UserControl
1919
{
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-
2920
public static readonly StyledProperty<bool> IsExpandedProperty =
3021
AvaloniaProperty.Register<BranchTreeNodeIcon, bool>(nameof(IsExpanded));
3122

@@ -35,16 +26,23 @@ public bool IsExpanded
3526
set => SetValue(IsExpandedProperty, value);
3627
}
3728

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)
3936
{
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();
4241
}
4342

4443
private void UpdateContent()
4544
{
46-
var node = Node;
47-
if (node == null)
45+
if (DataContext is not ViewModels.BranchTreeNode node)
4846
{
4947
Content = null;
5048
return;

0 commit comments

Comments
 (0)