diff --git a/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs b/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs index c0f8de3bd6a8..8325e30fd53d 100644 --- a/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs +++ b/src/Controls/src/Core/Platform/Windows/Extensions/AccessibilityExtensions.cs @@ -25,7 +25,10 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con _defaultAutomationPropertiesName = currentValue = (string)Control.GetValue(NativeAutomationProperties.NameProperty); } - var elemValue = (string)Element.GetValue(SemanticProperties.DescriptionProperty); +#pragma warning disable CS0618 // Type or member is obsolete + var elemValue = (string)Element.GetValue(AutomationProperties.NameProperty); +#pragma warning restore CS0618 // Type or member is obsolete + string newValue = !string.IsNullOrWhiteSpace(elemValue) ? elemValue : _defaultAutomationPropertiesName; if (currentValue is null || currentValue != newValue) @@ -85,7 +88,10 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con _defaultAutomationPropertiesHelpText = currentValue = (string)Control.GetValue(NativeAutomationProperties.HelpTextProperty); } - var elemValue = (string)Element.GetValue(SemanticProperties.HintProperty); +#pragma warning disable CS0618 // Type or member is obsolete + var elemValue = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete + string newValue = !string.IsNullOrWhiteSpace(elemValue) ? elemValue : _defaultAutomationPropertiesHelpText; if (currentValue is null || newValue != currentValue) @@ -117,8 +123,9 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con { _defaultAutomationPropertiesLabeledBy = currentValue = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty); } - - var elemValue = (VisualElement)Element.GetValue(SemanticProperties.DescriptionProperty); +#pragma warning disable CS0618 // Type or member is obsolete + var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty); +#pragma warning restore CS0618 // Type or member is obsolete FrameworkElement? nativeElement = null; if (mauiContext != null) @@ -130,7 +137,9 @@ public static void SetAutomationPropertiesAutomationId(this FrameworkElement Con if (currentValue is null || newValue != currentValue) { - Control.SetValue(SemanticProperties.DescriptionProperty, newValue); +#pragma warning disable CS0618 // Type or member is obsolete + Control.SetValue(AutomationProperties.LabeledByProperty, newValue); +#pragma warning restore CS0618 // Type or member is obsolete } return _defaultAutomationPropertiesLabeledBy; @@ -152,8 +161,11 @@ public static void SetBackButtonTitle(this PageControl Control, Element? Element static string ConcatenateNameAndHint(Element Element) { - var name = (string)Element.GetValue(SemanticProperties.DescriptionProperty); - var hint = (string)Element.GetValue(SemanticProperties.HintProperty); +#pragma warning disable CS0618 // Type or member is obsolete + var name = (string)Element.GetValue(AutomationProperties.NameProperty); + + var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty); +#pragma warning restore CS0618 // Type or member is obsolete string separator = string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint) ? "" : ". "; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml new file mode 100644 index 000000000000..b5aac6c0936b --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml.cs new file mode 100644 index 000000000000..deeab279448a --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml.cs @@ -0,0 +1,19 @@ +namespace Maui.Controls.Sample.Issues +{ + [Issue(IssueTracker.Github, 31606, "Crash on Windows when SemanticProperties.Description is set for ToolbarItem", PlatformAffected.UWP)] + public partial class Issue31606 : NavigationPage + { + public Issue31606() + { + Navigation.PushAsync(new Issue31606MainPage()); + } + } + + public partial class Issue31606MainPage : ContentPage + { + public Issue31606MainPage() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31606.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31606.cs new file mode 100644 index 000000000000..dac723116f4d --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31606.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue31606 : _IssuesUITest +{ + public Issue31606(TestDevice testDevice) : base(testDevice) { } + + public override string Issue => "Crash on Windows when SemanticProperties.Description is set for ToolbarItem"; + + [Test] + [Category(UITestCategories.Accessibility)] + public void SettingSemanticPropertiesDescriptionDoesNotCrash() + { + App.WaitForElement("TestStatus"); + } +} \ No newline at end of file