From b6f32afea72fbafddfe9c382b49809129e0cd8ec Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Wed, 22 Apr 2020 19:59:01 +0200 Subject: [PATCH] Fixing data automation peer for ribbon group #647 --- .../Peers/RibbonControlDataAutomationPeer.cs | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) 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