From 653f761cf89de4c9c2c1361738784fd0919ebe0f Mon Sep 17 00:00:00 2001 From: noubar Date: Wed, 24 Jul 2024 19:59:29 +0200 Subject: [PATCH 1/2] #2166 automatiopeer for numericupdown --- .../ExampleViews/TextExamples.xaml | 3 ++- .../Peers/NumericUpdDownAutomationPeer.cs | 26 +++++++++++++++++++ src/MahApps.Metro/Controls/NumericUpDown.cs | 11 ++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/TextExamples.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/TextExamples.xaml index 9bfac4b50b..c555c141ec 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/TextExamples.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/TextExamples.xaml @@ -376,7 +376,8 @@ - diff --git a/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs b/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs new file mode 100644 index 0000000000..bd8810b19a --- /dev/null +++ b/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs @@ -0,0 +1,26 @@ +using System.Windows.Automation; +using System.Windows.Automation.Peers; +using System.Windows.Automation.Provider; +using JetBrains.Annotations; +using MahApps.Metro.Controls; + +namespace MahApps.Metro.Automation.Peers +{ + public class NumericUpdDownAutomationPeer : FrameworkElementAutomationPeer + { + public NumericUpdDownAutomationPeer([NotNull] NumericUpDown owner) + : base(owner) + { + } + protected override string GetClassNameCore() + { + return "NumericUpDown"; + } + protected override AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Edit; + } + + } + +} diff --git a/src/MahApps.Metro/Controls/NumericUpDown.cs b/src/MahApps.Metro/Controls/NumericUpDown.cs index 41edb0d2db..e3da852c06 100644 --- a/src/MahApps.Metro/Controls/NumericUpDown.cs +++ b/src/MahApps.Metro/Controls/NumericUpDown.cs @@ -16,6 +16,9 @@ using System.Windows.Input; using JetBrains.Annotations; using MahApps.Metro.ValueBoxes; +using MahApps.Metro.Automation.Peers; +using System.Windows.Automation; +using System.Windows.Automation.Peers; namespace MahApps.Metro.Controls { @@ -1019,6 +1022,14 @@ public override void OnApplyTemplate() this.scrollViewer = null; } + /// + /// Creates AutomationPeer () + /// + protected override AutomationPeer OnCreateAutomationPeer() + { + return new NumericUpdDownAutomationPeer(this); + } + private void ToggleReadOnlyMode(bool isReadOnly) { if (this.repeatUp is null || this.repeatDown is null || this.valueTextBox is null) From a3b594947b4ade3159a306c9e9aa8294d2bd9c25 Mon Sep 17 00:00:00 2001 From: punker76 Date: Sun, 28 Jul 2024 23:14:08 +0200 Subject: [PATCH 2/2] #2166 add file header --- .../Peers/NumericUpdDownAutomationPeer.cs | 16 +++++++++------- src/MahApps.Metro/Controls/NumericUpDown.cs | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs b/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs index bd8810b19a..98be8bf237 100644 --- a/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs +++ b/src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs @@ -1,6 +1,8 @@ -using System.Windows.Automation; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + using System.Windows.Automation.Peers; -using System.Windows.Automation.Provider; using JetBrains.Annotations; using MahApps.Metro.Controls; @@ -8,19 +10,19 @@ namespace MahApps.Metro.Automation.Peers { public class NumericUpdDownAutomationPeer : FrameworkElementAutomationPeer { - public NumericUpdDownAutomationPeer([NotNull] NumericUpDown owner) + public NumericUpdDownAutomationPeer([NotNull] NumericUpDown owner) : base(owner) { } + protected override string GetClassNameCore() { - return "NumericUpDown"; + return nameof(NumericUpDown); } + protected override AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Edit; } - } - -} +} \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/NumericUpDown.cs b/src/MahApps.Metro/Controls/NumericUpDown.cs index e3da852c06..9eb740746c 100644 --- a/src/MahApps.Metro/Controls/NumericUpDown.cs +++ b/src/MahApps.Metro/Controls/NumericUpDown.cs @@ -17,7 +17,6 @@ using JetBrains.Annotations; using MahApps.Metro.ValueBoxes; using MahApps.Metro.Automation.Peers; -using System.Windows.Automation; using System.Windows.Automation.Peers; namespace MahApps.Metro.Controls