Skip to content

Commit e3171b2

Browse files
author
msftbot[bot]
authored
RadialGauge UIA improvements (#3544)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> ## Fixes # <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> Fixes #3537 , Fixes #3539 , Fixes #3542 (this PR is all we can do, see microsoft/microsoft-ui-xaml#3469) <!-- Add a brief overview here of the feature/bug & fix. --> The issues with the sample were caused by microsoft/microsoft-ui-xaml#3467 , switching to RangeBaseAutomationPeer as base class for the RadialGauge peer fixes that. Afaik, the only thing we can (and should do) for #3542 is raise the appropriate event on the AutomationPeer. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> RadialGauge is not accessible ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> RadialGauge is accessible ## PR Checklist Please check if your PR fulfills the following requirements: - [x] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [x] Tests for the changes have been added (for bug fixes / features) (if applicable) - [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [Maybe?] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information I left out the RangeSelector from this PR as fixing that controls behavior needs more discussion on how to approach that.
2 parents b353c78 + 3d79d7b commit e3171b2

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/RadialGauge/RadialGauge.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ protected override void OnValueChanged(double oldValue, double newValue)
469469
{
470470
OnValueChanged(this);
471471
base.OnValueChanged(oldValue, newValue);
472+
if (AutomationPeer.ListenerExists(AutomationEvents.LiveRegionChanged))
473+
{
474+
var peer = FrameworkElementAutomationPeer.FromElement(this) as RadialGaugeAutomationPeer;
475+
peer?.RaiseValueChangedEvent(oldValue, newValue);
476+
}
472477
}
473478

474479
private static void OnValueChanged(DependencyObject d)

Microsoft.Toolkit.Uwp.UI.Controls/RadialGauge/RadialGaugeAutomationPeer.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6+
using Windows.Foundation;
7+
using Windows.UI.Xaml.Automation;
68
using Windows.UI.Xaml.Automation.Peers;
79
using Windows.UI.Xaml.Automation.Provider;
810

@@ -12,7 +14,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls
1214
/// Exposes <see cref="RadialGauge"/> to Microsoft UI Automation.
1315
/// </summary>
1416
public class RadialGaugeAutomationPeer :
15-
FrameworkElementAutomationPeer,
17+
RangeBaseAutomationPeer,
1618
IRangeValueProvider
1719
{
1820
/// <summary>
@@ -25,25 +27,25 @@ public RadialGaugeAutomationPeer(RadialGauge owner)
2527
}
2628

2729
/// <inheritdoc/>
28-
public bool IsReadOnly => !((RadialGauge)Owner).IsInteractive;
30+
public new bool IsReadOnly => !((RadialGauge)Owner).IsInteractive;
2931

3032
/// <inheritdoc/>
31-
public double LargeChange => ((RadialGauge)Owner).StepSize;
33+
public new double LargeChange => ((RadialGauge)Owner).StepSize;
3234

3335
/// <inheritdoc/>
34-
public double Maximum => ((RadialGauge)Owner).Maximum;
36+
public new double Maximum => ((RadialGauge)Owner).Maximum;
3537

3638
/// <inheritdoc/>
37-
public double Minimum => ((RadialGauge)Owner).Minimum;
39+
public new double Minimum => ((RadialGauge)Owner).Minimum;
3840

3941
/// <inheritdoc/>
40-
public double SmallChange => ((RadialGauge)Owner).StepSize;
42+
public new double SmallChange => ((RadialGauge)Owner).StepSize;
4143

4244
/// <inheritdoc/>
43-
public double Value => ((RadialGauge)Owner).Value;
45+
public new double Value => ((RadialGauge)Owner).Value;
4446

4547
/// <inheritdoc/>
46-
public void SetValue(double value)
48+
public new void SetValue(double value)
4749
{
4850
((RadialGauge)Owner).Value = value;
4951
}
@@ -58,7 +60,7 @@ protected override IList<AutomationPeer> GetChildrenCore()
5860
protected override string GetNameCore()
5961
{
6062
var gauge = (RadialGauge)Owner;
61-
return "radial gauge. " + (string.IsNullOrWhiteSpace(gauge.Unit) ? "no unit specified. " : "unit " + gauge.Unit + ". ");
63+
return "radial gauge. " + (string.IsNullOrWhiteSpace(gauge.Unit) ? "no unit specified, " : "unit " + gauge.Unit + ", ") + Value;
6264
}
6365

6466
/// <inheritdoc/>
@@ -78,5 +80,15 @@ protected override AutomationControlType GetAutomationControlTypeCore()
7880
{
7981
return AutomationControlType.Custom;
8082
}
83+
84+
/// <summary>
85+
/// Raises the property changed event for this AutomationPeer for the provided identifier.
86+
/// </summary>
87+
/// <param name="oldValue">Old value</param>
88+
/// <param name="newValue">New value</param>
89+
public void RaiseValueChangedEvent(double oldValue, double newValue)
90+
{
91+
RaisePropertyChangedEvent(RangeValuePatternIdentifiers.ValueProperty, PropertyValue.CreateDouble(oldValue), PropertyValue.CreateDouble(newValue));
92+
}
8193
}
8294
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 Microsoft.Toolkit.Uwp.UI.Controls;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
8+
using Windows.UI.Xaml.Automation.Peers;
9+
10+
namespace UnitTests.UWP.UI.Controls
11+
{
12+
[TestClass]
13+
public class Test_RadialGauge
14+
{
15+
/// <summary>
16+
/// Verifies that the UIA name is valid and makes sense
17+
/// </summary>
18+
[TestCategory("Test_TextToolbar_Localization")]
19+
[UITestMethod]
20+
public void VerifyUIAName()
21+
{
22+
var gauge = new RadialGauge()
23+
{
24+
Minimum = 0,
25+
Maximum = 100,
26+
Value = 20
27+
};
28+
29+
var gaugePeer = FrameworkElementAutomationPeer.CreatePeerForElement(gauge);
30+
31+
Assert.IsTrue(gaugePeer.GetName().Contains(gauge.Value.ToString()), "Verify that the UIA name contains the value of the RadialGauge.");
32+
Assert.IsTrue(gaugePeer.GetName().Contains("no unit"), "The UIA name should indicate that unit was not specified.");
33+
34+
gauge.Unit = "KM/H";
35+
Assert.IsTrue(gaugePeer.GetName().Contains(gauge.Unit), "The UIA name should report the unit of the RadialGauge.");
36+
}
37+
}
38+
}

UnitTests/UnitTests.UWP/UnitTests.UWP.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<Compile Include="PrivateType.cs" />
180180
<Compile Include="Properties\AssemblyInfo.cs" />
181181
<Compile Include="Helpers\Test_WeakEventListener.cs" />
182+
<Compile Include="UI\Controls\Test_RadialGauge.cs" />
182183
<Compile Include="UI\Controls\Test_TextToolbar_Localization.cs" />
183184
<Compile Include="UI\Controls\Test_InfiniteCanvas_Regression.cs" />
184185
<Compile Include="UI\Controls\Test_TokenizingTextBox_General.cs" />
@@ -498,4 +499,4 @@
498499
<Target Name="AfterBuild">
499500
</Target>
500501
-->
501-
</Project>
502+
</Project>

0 commit comments

Comments
 (0)