diff --git a/Changelog.md b/Changelog.md index 26f745815..ac39890dd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ - [#758](../../issues/758) - Auto menu expanding not working for MenuItems with ItemSource binding - [#765](../../issues/765) - InRibbonGallery Resizing Issues - [#766](../../issues/766) - Resizing of InRibbonGallery in a DataTemplate does not work + - [#768](../../issues/768) - Accessibility Insights: "An onscreen element must not have a null" - ### Enhancements/Features - Many automation peers have been added and improved diff --git a/Fluent.Ribbon/Automation/Peers/TwoLineLabelAutomationPeer.cs b/Fluent.Ribbon/Automation/Peers/TwoLineLabelAutomationPeer.cs new file mode 100644 index 000000000..90730bc65 --- /dev/null +++ b/Fluent.Ribbon/Automation/Peers/TwoLineLabelAutomationPeer.cs @@ -0,0 +1,72 @@ +namespace Fluent.Automation.Peers +{ + using System.Collections.Generic; + using System.Windows.Automation.Peers; + using System.Windows.Automation.Provider; + using System.Windows.Controls; + + /// + /// for . + /// + public class TwoLineLabelAutomationPeer : FrameworkElementAutomationPeer + { + /// + /// Constructor. + /// + /// Owner of the AutomationPeer. + public TwoLineLabelAutomationPeer(TwoLineLabel owner) + : base(owner) + { + } + + /// + /// + /// + protected override List GetChildrenCore() + { + return null; + } + + /// + /// + /// + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Text; + } + + /// + /// + /// + /// + protected override string GetClassNameCore() + { + return "TwoLineLabel"; + } + + /// + protected override string GetNameCore() + { + return ((TwoLineLabel)this.Owner).Text; + } + + /// + /// + /// + protected override bool IsControlElementCore() + { + // Return false if TwoLineLabel is part of a ControlTemplate, otherwise return the base method + var tb = (TwoLineLabel)this.Owner; + var templatedParent = tb.TemplatedParent; + + // If the templatedParent is a ContentPresenter, this TextBlock is generated from a DataTemplate + if (templatedParent == null + || templatedParent is ContentPresenter) + { + return base.IsControlElementCore(); + } + + return false; + } + } +} \ No newline at end of file diff --git a/Fluent.Ribbon/Controls/TwoLineLabel.cs b/Fluent.Ribbon/Controls/TwoLineLabel.cs index b80e39569..d4ce82af6 100644 --- a/Fluent.Ribbon/Controls/TwoLineLabel.cs +++ b/Fluent.Ribbon/Controls/TwoLineLabel.cs @@ -4,6 +4,7 @@ namespace Fluent using System; using System.ComponentModel; using System.Windows; + using System.Windows.Automation.Peers; using System.Windows.Controls; using System.Windows.Markup; using Fluent.Internal.KnownBoxes; @@ -124,6 +125,9 @@ public override void OnApplyTemplate() this.UpdateTextRun(); } + /// + protected override AutomationPeer OnCreateAutomationPeer() => new Fluent.Automation.Peers.TwoLineLabelAutomationPeer(this); + #endregion #region Event handling