From 27683638f081af8238486f7bdcf49137275a14fc Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Mon, 12 Nov 2018 19:15:52 +0100 Subject: [PATCH] Adding automation peer for RadioButton #647 --- .../Peers/RadioButtonAutomationPeer.cs | 32 +++++++++++++++++++ .../Peers/ToggleButtonAutomationPeer.cs | 2 +- Fluent.Ribbon/Controls/RadioButton.cs | 7 ++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Fluent.Ribbon/Automation/Peers/RadioButtonAutomationPeer.cs diff --git a/Fluent.Ribbon/Automation/Peers/RadioButtonAutomationPeer.cs b/Fluent.Ribbon/Automation/Peers/RadioButtonAutomationPeer.cs new file mode 100644 index 000000000..b9ed9fc7f --- /dev/null +++ b/Fluent.Ribbon/Automation/Peers/RadioButtonAutomationPeer.cs @@ -0,0 +1,32 @@ +namespace Fluent.Automation.Peers +{ + using JetBrains.Annotations; + + /// + public class RadioButtonAutomationPeer : System.Windows.Automation.Peers.RadioButtonAutomationPeer + { + /// Initializes a new instance of the class. + /// The element associated with this automation peer. + public RadioButtonAutomationPeer([NotNull] RadioButton 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/Automation/Peers/ToggleButtonAutomationPeer.cs b/Fluent.Ribbon/Automation/Peers/ToggleButtonAutomationPeer.cs index 5a3a5bd8a..4dd6de123 100644 --- a/Fluent.Ribbon/Automation/Peers/ToggleButtonAutomationPeer.cs +++ b/Fluent.Ribbon/Automation/Peers/ToggleButtonAutomationPeer.cs @@ -5,7 +5,7 @@ /// public class ToggleButtonAutomationPeer : System.Windows.Automation.Peers.ToggleButtonAutomationPeer { - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// The element associated with this automation peer. public ToggleButtonAutomationPeer([NotNull] ToggleButton owner) : base(owner) diff --git a/Fluent.Ribbon/Controls/RadioButton.cs b/Fluent.Ribbon/Controls/RadioButton.cs index 65ee41c21..4bf5bb118 100644 --- a/Fluent.Ribbon/Controls/RadioButton.cs +++ b/Fluent.Ribbon/Controls/RadioButton.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,11 @@ void ILogicalChildSupport.RemoveLogicalChild(object child) { this.RemoveLogicalChild(child); } + + /// + protected override AutomationPeer OnCreateAutomationPeer() + { + return new Fluent.Automation.Peers.RadioButtonAutomationPeer(this); + } } } \ No newline at end of file