Skip to content

Commit f7ba305

Browse files
authored
Merge pull request #4508 from noubar/#2166-automatiopeer-numericupdown
#2166 automatiopeer for numericupdown
2 parents 509c9d7 + a3b5949 commit f7ba305

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/TextExamples.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@
376376
</mah:MetroHeader>
377377

378378
<mah:MetroHeader Header="Min">
379-
<mah:NumericUpDown Margin="{StaticResource ControlMargin}"
379+
<mah:NumericUpDown AutomationProperties.AutomationId="AutomationIdTested"
380+
Margin="{StaticResource ControlMargin}"
380381
mah:TextBoxHelper.ClearTextButton="True"
381382
Maximum="{Binding ElementName=NUD, Path=Maximum, Mode=OneWay}"
382383
Value="{Binding ElementName=NUD, Path=Minimum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Windows.Automation.Peers;
6+
using JetBrains.Annotations;
7+
using MahApps.Metro.Controls;
8+
9+
namespace MahApps.Metro.Automation.Peers
10+
{
11+
public class NumericUpdDownAutomationPeer : FrameworkElementAutomationPeer
12+
{
13+
public NumericUpdDownAutomationPeer([NotNull] NumericUpDown owner)
14+
: base(owner)
15+
{
16+
}
17+
18+
protected override string GetClassNameCore()
19+
{
20+
return nameof(NumericUpDown);
21+
}
22+
23+
protected override AutomationControlType GetAutomationControlTypeCore()
24+
{
25+
return AutomationControlType.Edit;
26+
}
27+
}
28+
}

src/MahApps.Metro/Controls/NumericUpDown.cs

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System.Windows.Input;
1717
using JetBrains.Annotations;
1818
using MahApps.Metro.ValueBoxes;
19+
using MahApps.Metro.Automation.Peers;
20+
using System.Windows.Automation.Peers;
1921

2022
namespace MahApps.Metro.Controls
2123
{
@@ -1019,6 +1021,14 @@ public override void OnApplyTemplate()
10191021
this.scrollViewer = null;
10201022
}
10211023

1024+
/// <summary>
1025+
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
1026+
/// </summary>
1027+
protected override AutomationPeer OnCreateAutomationPeer()
1028+
{
1029+
return new NumericUpdDownAutomationPeer(this);
1030+
}
1031+
10221032
private void ToggleReadOnlyMode(bool isReadOnly)
10231033
{
10241034
if (this.repeatUp is null || this.repeatDown is null || this.valueTextBox is null)

0 commit comments

Comments
 (0)