From 8ff8d68b8c3c968947dd965d964edbb99e21c6ce Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Mon, 3 Dec 2018 21:54:10 +0100 Subject: [PATCH] Adding automation peer for CheckBox #647 --- .../Peers/CheckBoxAutomationPeer.cs | 32 +++++++++++++++++++ Fluent.Ribbon/Controls/CheckBox.cs | 4 +++ 2 files changed, 36 insertions(+) create mode 100644 Fluent.Ribbon/Automation/Peers/CheckBoxAutomationPeer.cs diff --git a/Fluent.Ribbon/Automation/Peers/CheckBoxAutomationPeer.cs b/Fluent.Ribbon/Automation/Peers/CheckBoxAutomationPeer.cs new file mode 100644 index 000000000..61f246a47 --- /dev/null +++ b/Fluent.Ribbon/Automation/Peers/CheckBoxAutomationPeer.cs @@ -0,0 +1,32 @@ +namespace Fluent.Automation.Peers +{ + using JetBrains.Annotations; + + /// + public class CheckBoxAutomationPeer : System.Windows.Automation.Peers.ToggleButtonAutomationPeer + { + /// Initializes a new instance of the class. + /// The element associated with this automation peer. + public CheckBoxAutomationPeer([NotNull] CheckBox owner) + : base(owner) + { + } + + /// + protected override string GetNameCore() + { + var text = base.GetNameCore(); + var owner = (IHeaderedControl)this.Owner; + + if (string.IsNullOrEmpty(text)) + { + if (owner.Header is string headerString) + { + return headerString; + } + } + + return text; + } + } +} \ No newline at end of file diff --git a/Fluent.Ribbon/Controls/CheckBox.cs b/Fluent.Ribbon/Controls/CheckBox.cs index 056f57a7b..fb8c8e183 100644 --- a/Fluent.Ribbon/Controls/CheckBox.cs +++ b/Fluent.Ribbon/Controls/CheckBox.cs @@ -2,6 +2,7 @@ namespace Fluent { using System.Windows; + using System.Windows.Automation.Peers; using System.Windows.Data; using System.Windows.Markup; using Fluent.Internal.KnownBoxes; @@ -196,5 +197,8 @@ void ILogicalChildSupport.RemoveLogicalChild(object child) { this.RemoveLogicalChild(child); } + + /// + protected override AutomationPeer OnCreateAutomationPeer() => new Fluent.Automation.Peers.CheckBoxAutomationPeer(this); } } \ No newline at end of file