Skip to content

Commit

Permalink
Fixing data automation peer for ribbon group #647
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Apr 22, 2020
1 parent 4018384 commit b6f32af
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions Fluent.Ribbon/Automation/Peers/RibbonControlDataAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Fluent.Automation.Peers
{
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;

/// <summary>
/// Automation peer for ribbon control items.
Expand All @@ -18,13 +20,53 @@ public RibbonControlDataAutomationPeer(object item, ItemsControlAutomationPeer i
/// <inheritdoc />
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.DataItem;
return AutomationControlType.ListItem;
}

/// <inheritdoc />
protected override string GetClassNameCore()
{
return "ItemsControlItem";
var wrapperPeer = this.GetWrapperPeer();
return wrapperPeer?.GetClassName() ?? string.Empty;
}

/// <inheritdoc />
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);
}
}
}

0 comments on commit b6f32af

Please sign in to comment.