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

Fix ItemsControl Automation Again #8715

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
<Compile Include="System\Windows\Automation\Peers\InkPresenterAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\ItemAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\ItemsControlAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\ItemsControlElementAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\ItemsControlItemAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\ItemsControlWrapperAutomationPeer.cs" />
<Compile Include="System\Windows\Automation\Peers\IViewAutomationPeer.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Windows;
using System.Windows.Controls;

namespace System.Windows.Automation.Peers
{
// this class is a brother of ItemsControlItemAutomationPeer,
internal class ItemsControlElementAutomationPeer : ItemAutomationPeer
{
private AutomationPeer _elementAutomationPeer;

public ItemsControlElementAutomationPeer(UIElement element, AutomationPeer peer, ItemsControlWrapperAutomationPeer parent)
: base(element, parent)
{
_elementAutomationPeer = peer;
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return _elementAutomationPeer.GetAutomationControlType();
}

protected override string GetClassNameCore()
{
return _elementAutomationPeer.GetClassName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ public ItemsControlWrapperAutomationPeer(ItemsControl owner)

override protected ItemAutomationPeer CreateItemAutomationPeer(object item)
{
if (item is UIElement element)
{
// Some UIElements have their own automation peers, so we need to check for that.
var peer = element.CreateAutomationPeer();
if (peer is not null)
{
return new ItemsControlElementAutomationPeer(element, peer, this);
}

// Some other UIElements don't have their own automation peers, so we treat them as ItemsControlItems.
}

// If the item is not a UIElement, or if it is a UIElement that doesn't have its own automation peer,
// we create an ItemsControlItemAutomationPeer for it.
return new ItemsControlItemAutomationPeer(item, this);
}

Expand Down