Files
cefsharp/CefSharp.Wpf/Experimental/Accessibility/TabControlAutomationPeer.cs

53 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Media;
namespace CefSharp.Wpf.Experimental.Accessibility
{
/// <summary>
/// Default TabControl's AutomationPeer doesn’t know anything about the controls within it, since they’re loaded dynamically.
/// The purpose of this class is to fix this behavior.
/// </summary>
/// <remarks>
/// Taken from https://www.colinsalmcorner.com/post/genericautomationpeer--helping-the-coded-ui-framework-find-your-custom-controls
/// </remarks>
public class TabControlAutomationPeer : UIElementAutomationPeer
{
public TabControlAutomationPeer(UIElement owner) : base(owner)
{
}
protected override List<AutomationPeer> GetChildrenCore()
{
var list = base.GetChildrenCore();
list.AddRange(GetChildPeers(Owner));
return list;
}
private List<AutomationPeer> GetChildPeers(UIElement element)
{
var list = new List<AutomationPeer>();
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
var child = VisualTreeHelper.GetChild(element, i) as UIElement;
if (child != null)
{
var childPeer = CreatePeerForElement(child);
if (childPeer != null)
{
list.Add(childPeer);
}
else
{
list.AddRange(GetChildPeers(child));
}
}
}
return list;
}
}
}