Browse Source

Add dedicated automation peers for TreeView and TreeViewItem (#15653)

* Add TreeViewAutomationPeer for TreeView

* Add TreeViewItemAutomationPeer for TreeViewItem

* Add missing xml doc
pull/15701/head
Wiesław Šoltés 2 years ago
committed by GitHub
parent
commit
6aacd552c6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      src/Avalonia.Controls/Automation/Peers/TreeViewAutomationPeer.cs
  2. 16
      src/Avalonia.Controls/Automation/Peers/TreeViewItemAutomationPeer.cs
  3. 7
      src/Avalonia.Controls/TreeView.cs
  4. 7
      src/Avalonia.Controls/TreeViewItem.cs

16
src/Avalonia.Controls/Automation/Peers/TreeViewAutomationPeer.cs

@ -0,0 +1,16 @@
using Avalonia.Controls;
namespace Avalonia.Automation.Peers;
public class TreeViewAutomationPeer : ItemsControlAutomationPeer
{
public TreeViewAutomationPeer(TreeView owner)
: base(owner)
{
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Tree;
}
}

16
src/Avalonia.Controls/Automation/Peers/TreeViewItemAutomationPeer.cs

@ -0,0 +1,16 @@
using Avalonia.Controls;
namespace Avalonia.Automation.Peers;
public class TreeViewItemAutomationPeer : ItemsControlAutomationPeer
{
public TreeViewItemAutomationPeer(TreeViewItem owner)
: base(owner)
{
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.TreeItem;
}
}

7
src/Avalonia.Controls/TreeView.cs

@ -6,6 +6,7 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Automation.Peers;
using Avalonia.Collections;
using Avalonia.Controls.Generators;
using Avalonia.Controls.Primitives;
@ -298,6 +299,12 @@ namespace Avalonia.Controls
return TreeItemFromContainer(this, container);
}
/// <inheritdoc />
protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeViewAutomationPeer(this);
}
private protected override void OnItemsViewCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
base.OnItemsViewCollectionChanged(sender, e);

7
src/Avalonia.Controls/TreeViewItem.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Primitives;
@ -93,6 +94,12 @@ namespace Avalonia.Controls
internal TreeView? TreeViewOwner => _treeView;
/// <inheritdoc />
protected override AutomationPeer OnCreateAutomationPeer()
{
return new TreeViewItemAutomationPeer(this);
}
protected internal override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
{
return EnsureTreeView().CreateContainerForItemOverride(item, index, recycleKey);

Loading…
Cancel
Save