Skip to content

Commit 5531aa9

Browse files
[release/9.0.1xx-sr11] [Windows] Revert cleanup of AccessibilityExtensions (#31758)
* revert * test --------- Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com>
1 parent 7c4f71a commit 5531aa9

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con
2525
_defaultAutomationPropertiesName = currentValue = (string)Control.GetValue(NativeAutomationProperties.NameProperty);
2626
}
2727

28-
var elemValue = (string)Element.GetValue(SemanticProperties.DescriptionProperty);
28+
#pragma warning disable CS0618 // Type or member is obsolete
29+
var elemValue = (string)Element.GetValue(AutomationProperties.NameProperty);
30+
#pragma warning restore CS0618 // Type or member is obsolete
31+
2932
string newValue = !string.IsNullOrWhiteSpace(elemValue) ? elemValue : _defaultAutomationPropertiesName;
3033

3134
if (currentValue is null || currentValue != newValue)
@@ -85,7 +88,10 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con
8588
_defaultAutomationPropertiesHelpText = currentValue = (string)Control.GetValue(NativeAutomationProperties.HelpTextProperty);
8689
}
8790

88-
var elemValue = (string)Element.GetValue(SemanticProperties.HintProperty);
91+
#pragma warning disable CS0618 // Type or member is obsolete
92+
var elemValue = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
93+
#pragma warning restore CS0618 // Type or member is obsolete
94+
8995
string newValue = !string.IsNullOrWhiteSpace(elemValue) ? elemValue : _defaultAutomationPropertiesHelpText;
9096

9197
if (currentValue is null || newValue != currentValue)
@@ -117,8 +123,9 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con
117123
{
118124
_defaultAutomationPropertiesLabeledBy = currentValue = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty);
119125
}
120-
121-
var elemValue = (VisualElement)Element.GetValue(SemanticProperties.DescriptionProperty);
126+
#pragma warning disable CS0618 // Type or member is obsolete
127+
var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty);
128+
#pragma warning restore CS0618 // Type or member is obsolete
122129
FrameworkElement? nativeElement = null;
123130

124131
if (mauiContext != null)
@@ -130,7 +137,9 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con
130137

131138
if (currentValue is null || newValue != currentValue)
132139
{
133-
Control.SetValue(SemanticProperties.DescriptionProperty, newValue);
140+
#pragma warning disable CS0618 // Type or member is obsolete
141+
Control.SetValue(AutomationProperties.LabeledByProperty, newValue);
142+
#pragma warning restore CS0618 // Type or member is obsolete
134143
}
135144

136145
return _defaultAutomationPropertiesLabeledBy;
@@ -152,8 +161,11 @@ public static void SetBackButtonTitle(this PageControl Control, Element? Element
152161

153162
static string ConcatenateNameAndHint(Element Element)
154163
{
155-
var name = (string)Element.GetValue(SemanticProperties.DescriptionProperty);
156-
var hint = (string)Element.GetValue(SemanticProperties.HintProperty);
164+
#pragma warning disable CS0618 // Type or member is obsolete
165+
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
166+
167+
var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
168+
#pragma warning restore CS0618 // Type or member is obsolete
157169

158170
string separator = string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint) ? "" : ". ";
159171

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue31606MainPage">
5+
<ContentPage.ToolbarItems>
6+
<ToolbarItem Order="Primary" Text="Menu Option 1" SemanticProperties.Description="Info about option 1" />
7+
<ToolbarItem Order="Secondary" Text="Menu Option 2" SemanticProperties.Description="Info about option 2" />
8+
</ContentPage.ToolbarItems>
9+
10+
<VerticalStackLayout Padding="10" HorizontalOptions="Start">
11+
<Label Text="Semantic properties test" FontAttributes="Bold"/>
12+
13+
<Label Text="1) Image with a description and a hint:"/>
14+
<Image Source="coffee.png" WidthRequest="150" HeightRequest="150"
15+
SemanticProperties.Description="Like"
16+
SemanticProperties.Hint="Like this post."/>
17+
18+
<Label Text="2) Label with a semantic heading level:"/>
19+
<Label Text="Installation" SemanticProperties.HeadingLevel="Level2" />
20+
21+
<Label AutomationId="TestStatus" Text="If this label appears, the test passed."/>
22+
</VerticalStackLayout>
23+
</ContentPage>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 31606, "Crash on Windows when SemanticProperties.Description is set for ToolbarItem", PlatformAffected.UWP)]
4+
public partial class Issue31606 : NavigationPage
5+
{
6+
public Issue31606()
7+
{
8+
Navigation.PushAsync(new Issue31606MainPage());
9+
}
10+
}
11+
12+
public partial class Issue31606MainPage : ContentPage
13+
{
14+
public Issue31606MainPage()
15+
{
16+
InitializeComponent();
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue31606 : _IssuesUITest
8+
{
9+
public Issue31606(TestDevice testDevice) : base(testDevice) { }
10+
11+
public override string Issue => "Crash on Windows when SemanticProperties.Description is set for ToolbarItem";
12+
13+
[Test]
14+
[Category(UITestCategories.Accessibility)]
15+
public void SettingSemanticPropertiesDescriptionDoesNotCrash()
16+
{
17+
App.WaitForElement("TestStatus");
18+
}
19+
}

0 commit comments

Comments
 (0)