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

Add dedicated automation peers for TreeView and TreeViewItem #15653

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Avalonia.Controls/Automation/Peers/TreeViewAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions src/Avalonia.Controls/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -298,6 +299,12 @@ static IEnumerable<Control> GetRealizedContainers(ItemsControl itemsControl)
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);
Expand Down
7 changes: 7 additions & 0 deletions src/Avalonia.Controls/TreeViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,12 @@ public int Level

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);
Expand Down