mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-05 02:54:59 +00:00
refactor: simpfy SourceGit.Views.BranchTreeNodeIcon
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
fd935259aa
commit
1f0ab2bfec
2 changed files with 13 additions and 17 deletions
|
@ -55,9 +55,7 @@
|
||||||
DoubleTapped="OnDoubleTappedBranchNode">
|
DoubleTapped="OnDoubleTappedBranchNode">
|
||||||
|
|
||||||
<!-- Icon -->
|
<!-- Icon -->
|
||||||
<v:BranchTreeNodeIcon Grid.Column="0"
|
<v:BranchTreeNodeIcon Grid.Column="0" IsExpanded="{Binding IsExpanded}"/>
|
||||||
Node="{Binding}"
|
|
||||||
IsExpanded="{Binding IsExpanded}"/>
|
|
||||||
|
|
||||||
<!-- Name -->
|
<!-- Name -->
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
|
|
|
@ -17,15 +17,6 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public class BranchTreeNodeIcon : UserControl
|
public class BranchTreeNodeIcon : UserControl
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<ViewModels.BranchTreeNode> NodeProperty =
|
|
||||||
AvaloniaProperty.Register<BranchTreeNodeIcon, ViewModels.BranchTreeNode>(nameof(Node));
|
|
||||||
|
|
||||||
public ViewModels.BranchTreeNode Node
|
|
||||||
{
|
|
||||||
get => GetValue(NodeProperty);
|
|
||||||
set => SetValue(NodeProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsExpandedProperty =
|
public static readonly StyledProperty<bool> IsExpandedProperty =
|
||||||
AvaloniaProperty.Register<BranchTreeNodeIcon, bool>(nameof(IsExpanded));
|
AvaloniaProperty.Register<BranchTreeNodeIcon, bool>(nameof(IsExpanded));
|
||||||
|
|
||||||
|
@ -35,16 +26,23 @@ namespace SourceGit.Views
|
||||||
set => SetValue(IsExpandedProperty, value);
|
set => SetValue(IsExpandedProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BranchTreeNodeIcon()
|
protected override void OnDataContextChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
NodeProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, _) => icon.UpdateContent());
|
base.OnDataContextChanged(e);
|
||||||
IsExpandedProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, _) => icon.UpdateContent());
|
UpdateContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged(change);
|
||||||
|
|
||||||
|
if (change.Property == IsExpandedProperty)
|
||||||
|
UpdateContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateContent()
|
private void UpdateContent()
|
||||||
{
|
{
|
||||||
var node = Node;
|
if (DataContext is not ViewModels.BranchTreeNode node)
|
||||||
if (node == null)
|
|
||||||
{
|
{
|
||||||
Content = null;
|
Content = null;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue