Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2166 automatiopeer for numericupdown #4508

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading