diff --git a/src/Avalonia.Controls/Automation/Peers/TreeViewAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/TreeViewAutomationPeer.cs new file mode 100644 index 00000000000..5bb0dcaa551 --- /dev/null +++ b/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; + } +} diff --git a/src/Avalonia.Controls/Automation/Peers/TreeViewItemAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/TreeViewItemAutomationPeer.cs new file mode 100644 index 00000000000..9629a752677 --- /dev/null +++ b/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; + } +} diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index 56a5999f295..c29dfd583f2 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -6,6 +6,7 @@ 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 @@ static IEnumerable GetRealizedContainers(ItemsControl itemsControl) return TreeItemFromContainer(this, container); } + /// + protected override AutomationPeer OnCreateAutomationPeer() + { + return new TreeViewAutomationPeer(this); + } + private protected override void OnItemsViewCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { base.OnItemsViewCollectionChanged(sender, e); diff --git a/src/Avalonia.Controls/TreeViewItem.cs b/src/Avalonia.Controls/TreeViewItem.cs index a48706cb19c..1e68b08ae4f 100644 --- a/src/Avalonia.Controls/TreeViewItem.cs +++ b/src/Avalonia.Controls/TreeViewItem.cs @@ -2,6 +2,7 @@ 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 @@ public int Level internal TreeView? TreeViewOwner => _treeView; + /// + 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);