diff --git a/Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs b/Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs index a5f9a52e5..e10c825dc 100644 --- a/Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs +++ b/Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs @@ -1,6 +1,8 @@ namespace Fluent.Automation.Peers { + using System.Windows; using System.Windows.Automation.Peers; + using System.Windows.Controls; /// /// Automation peer for ribbon control items. @@ -18,13 +20,53 @@ public RibbonControlDataAutomationPeer(object item, ItemsControlAutomationPeer i /// protected override AutomationControlType GetAutomationControlTypeCore() { - return AutomationControlType.DataItem; + return AutomationControlType.ListItem; } /// protected override string GetClassNameCore() { - return "ItemsControlItem"; + var wrapperPeer = this.GetWrapperPeer(); + return wrapperPeer?.GetClassName() ?? string.Empty; + } + + /// + public override object GetPattern(PatternInterface patternInterface) + { + // Doesnt implement any patterns of its own, so just forward to the wrapper peer. + var wrapperPeer = this.GetWrapperPeer(); + + return wrapperPeer?.GetPattern(patternInterface); + } + + private UIElement GetWrapper() + { + var itemsControlAutomationPeer = this.ItemsControlAutomationPeer; + + var owner = (ItemsControl)itemsControlAutomationPeer?.Owner; + return owner?.ItemContainerGenerator.ContainerFromItem(this.Item) as UIElement; + } + + private AutomationPeer GetWrapperPeer() + { + var wrapper = this.GetWrapper(); + if (wrapper is null) + { + return null; + } + + var wrapperPeer = UIElementAutomationPeer.CreatePeerForElement(wrapper); + if (!(wrapperPeer is null)) + { + return wrapperPeer; + } + + if (wrapper is FrameworkElement element) + { + return new FrameworkElementAutomationPeer(element); + } + + return new UIElementAutomationPeer(wrapper); } } } \ No newline at end of file