diff --git a/src/Avalonia.Controls/TreeViewItem.cs b/src/Avalonia.Controls/TreeViewItem.cs index 022e1a74b1..5674874c01 100644 --- a/src/Avalonia.Controls/TreeViewItem.cs +++ b/src/Avalonia.Controls/TreeViewItem.cs @@ -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; @@ -22,11 +22,10 @@ namespace Avalonia.Controls /// /// Defines the property. /// - public static readonly DirectProperty IsExpandedProperty = - AvaloniaProperty.RegisterDirect( + public static readonly StyledProperty IsExpandedProperty = + AvaloniaProperty.Register( nameof(IsExpanded), - o => o.IsExpanded, - (o, v) => o.IsExpanded = v); + defaultBindingMode: BindingMode.TwoWay); /// /// Defines the property. @@ -46,7 +45,6 @@ namespace Avalonia.Controls private TreeView? _treeView; private Control? _header; - private bool _isExpanded; private int _level; private bool _templateApplied; private bool _deferredBringIntoViewFlag; @@ -68,8 +66,8 @@ namespace Avalonia.Controls /// public bool IsExpanded { - get { return _isExpanded; } - set { SetAndRaise(IsExpandedProperty, ref _isExpanded, value); } + get => GetValue(IsExpandedProperty); + set => SetValue(IsExpandedProperty, value); } /// @@ -77,8 +75,8 @@ namespace Avalonia.Controls /// public bool IsSelected { - get { return GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } + get => GetValue(IsSelectedProperty); + set => SetValue(IsSelectedProperty, value); } /// @@ -86,8 +84,8 @@ namespace Avalonia.Controls /// 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; @@ -115,11 +113,6 @@ namespace Avalonia.Controls } } - protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) - { - base.OnDetachedFromLogicalTree(e); - } - protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e) { if (e.TargetObject == this) @@ -266,7 +259,7 @@ namespace Avalonia.Controls } /// - /// Invoked when the event occurs in the header. + /// Invoked when the event occurs in the header. /// protected virtual void OnHeaderDoubleTapped(TappedEventArgs e) {