Skip to content

Commit

Permalink
MahApps#2166 automatiopeer for numericupdown
Browse files Browse the repository at this point in the history
  • Loading branch information
noubar committed Jul 24, 2024
1 parent 509c9d7 commit 653f761
Show file tree
Hide file tree
Showing 3 changed files with 39 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
26 changes: 26 additions & 0 deletions src/MahApps.Metro/Automation/Peers/NumericUpdDownAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}

}
11 changes: 11 additions & 0 deletions src/MahApps.Metro/Controls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -1019,6 +1022,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 653f761

Please sign in to comment.