|
|
@ -6,6 +6,7 @@ using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Templates; |
|
|
using Avalonia.Controls.Templates; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.LogicalTree; |
|
|
using Avalonia.LogicalTree; |
|
|
|
|
|
using Avalonia.Threading; |
|
|
|
|
|
|
|
|
namespace Avalonia.Controls |
|
|
namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
@ -45,6 +46,8 @@ namespace Avalonia.Controls |
|
|
private IControl? _header; |
|
|
private IControl? _header; |
|
|
private bool _isExpanded; |
|
|
private bool _isExpanded; |
|
|
private int _level; |
|
|
private int _level; |
|
|
|
|
|
private bool _templateApplied; |
|
|
|
|
|
private bool _deferredBringIntoViewFlag; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Initializes static members of the <see cref="TreeViewItem"/> class.
|
|
|
/// Initializes static members of the <see cref="TreeViewItem"/> class.
|
|
|
@ -136,15 +139,24 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
|
protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e) |
|
|
protected virtual void OnRequestBringIntoView(RequestBringIntoViewEventArgs e) |
|
|
{ |
|
|
{ |
|
|
if (e.TargetObject == this && _header != null) |
|
|
if (e.TargetObject == this) |
|
|
{ |
|
|
{ |
|
|
var m = _header.TransformToVisual(this); |
|
|
if (!_templateApplied) |
|
|
|
|
|
{ |
|
|
|
|
|
_deferredBringIntoViewFlag = true; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (m.HasValue) |
|
|
if (_header != null) |
|
|
{ |
|
|
{ |
|
|
var bounds = new Rect(_header.Bounds.Size); |
|
|
var m = _header.TransformToVisual(this); |
|
|
var rect = bounds.TransformToAABB(m.Value); |
|
|
|
|
|
e.TargetRect = rect; |
|
|
if (m.HasValue) |
|
|
|
|
|
{ |
|
|
|
|
|
var bounds = new Rect(_header.Bounds.Size); |
|
|
|
|
|
var rect = bounds.TransformToAABB(m.Value); |
|
|
|
|
|
e.TargetRect = rect; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -187,6 +199,12 @@ namespace Avalonia.Controls |
|
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
|
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) |
|
|
{ |
|
|
{ |
|
|
_header = e.NameScope.Find<IControl>("PART_Header"); |
|
|
_header = e.NameScope.Find<IControl>("PART_Header"); |
|
|
|
|
|
_templateApplied = true; |
|
|
|
|
|
if (_deferredBringIntoViewFlag) |
|
|
|
|
|
{ |
|
|
|
|
|
_deferredBringIntoViewFlag = false; |
|
|
|
|
|
Dispatcher.UIThread.Post(this.BringIntoView); // must use the Dispatcher, otherwise the TreeView doesn't scroll
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static int CalculateDistanceFromLogicalParent<T>(ILogical? logical, int @default = -1) where T : class |
|
|
private static int CalculateDistanceFromLogicalParent<T>(ILogical? logical, int @default = -1) where T : class |
|
|
|