Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch TreeViewItem.IsExpanded to a StyledProperty #10137

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions src/Avalonia.Controls/TreeViewItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.LogicalTree;
using Avalonia.Threading;
Expand All @@ -22,11 +22,10 @@ public class TreeViewItem : HeaderedItemsControl, ISelectable
/// <summary>
/// Defines the <see cref="IsExpanded"/> property.
/// </summary>
public static readonly DirectProperty<TreeViewItem, bool> IsExpandedProperty =
AvaloniaProperty.RegisterDirect<TreeViewItem, bool>(
public static readonly StyledProperty<bool> IsExpandedProperty =
AvaloniaProperty.Register<TreeViewItem, bool>(
nameof(IsExpanded),
o => o.IsExpanded,
(o, v) => o.IsExpanded = v);
defaultBindingMode: BindingMode.TwoWay);

/// <summary>
/// Defines the <see cref="IsSelected"/> property.
Expand All @@ -46,7 +45,6 @@ public class TreeViewItem : HeaderedItemsControl, ISelectable

private TreeView? _treeView;
private Control? _header;
private bool _isExpanded;
private int _level;
private bool _templateApplied;
private bool _deferredBringIntoViewFlag;
Expand All @@ -68,26 +66,26 @@ static TreeViewItem()
/// </summary>
public bool IsExpanded
{
get { return _isExpanded; }
set { SetAndRaise(IsExpandedProperty, ref _isExpanded, value); }
get => GetValue(IsExpandedProperty);
set => SetValue(IsExpandedProperty, value);
}

/// <summary>
/// Gets or sets the selection state of the item.
/// </summary>
public bool IsSelected
{
get { return GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
get => GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, value);
}

/// <summary>
/// Gets the level/indentation of the item.
/// </summary>
public int Level
{
get { return _level; }
private set { SetAndRaise(LevelProperty, ref _level, value); }
get => _level;
private set => SetAndRaise(LevelProperty, ref _level, value);
}

internal TreeView? TreeViewOwner => _treeView;
Expand Down Expand Up @@ -115,11 +113,6 @@ protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e
}
}

protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnDetachedFromLogicalTree(e);
}

protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e)
{
if (e.TargetObject == this)
Expand Down Expand Up @@ -266,7 +259,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
}

/// <summary>
/// Invoked when the <see cref="DoubleTapped"/> event occurs in the header.
/// Invoked when the <see cref="InputElement.DoubleTapped"/> event occurs in the header.
/// </summary>
protected virtual void OnHeaderDoubleTapped(TappedEventArgs e)
{
Expand Down