Skip to content

Commit

Permalink
Merge pull request #4508 from noubar/#2166-automatiopeer-numericupdown
Browse files Browse the repository at this point in the history
#2166 automatiopeer for numericupdown
  • Loading branch information
punker76 authored Jul 28, 2024
2 parents 509c9d7 + a3b5949 commit f7ba305
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@
</mah:MetroHeader>

<mah:MetroHeader Header="Min">
<mah:NumericUpDown Margin="{StaticResource ControlMargin}"
<mah:NumericUpDown AutomationProperties.AutomationId="AutomationIdTested"
Margin="{StaticResource ControlMargin}"
mah:TextBoxHelper.ClearTextButton="True"
Maximum="{Binding ElementName=NUD, Path=Maximum, Mode=OneWay}"
Value="{Binding ElementName=NUD, Path=Minimum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Expand Down
28 changes: 28 additions & 0 deletions src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 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 nameof(NumericUpDown);
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Edit;
}
}
}
10 changes: 10 additions & 0 deletions src/MahApps.Metro/Controls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using System.Windows.Input;
using JetBrains.Annotations;
using MahApps.Metro.ValueBoxes;
using MahApps.Metro.Automation.Peers;
using System.Windows.Automation.Peers;

namespace MahApps.Metro.Controls
{
Expand Down Expand Up @@ -1019,6 +1021,14 @@ public override void OnApplyTemplate()
this.scrollViewer = null;
}

/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
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)
Expand Down

0 comments on commit f7ba305

Please sign in to comment.