Skip to content
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 @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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) ? "" : ". ";

Expand Down
23 changes: 23 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue31606MainPage">
<ContentPage.ToolbarItems>
<ToolbarItem Order="Primary" Text="Menu Option 1" SemanticProperties.Description="Info about option 1" />
<ToolbarItem Order="Secondary" Text="Menu Option 2" SemanticProperties.Description="Info about option 2" />
</ContentPage.ToolbarItems>

<VerticalStackLayout Padding="10" HorizontalOptions="Start">
<Label Text="Semantic properties test" FontAttributes="Bold"/>

<Label Text="1) Image with a description and a hint:"/>
<Image Source="coffee.png" WidthRequest="150" HeightRequest="150"
SemanticProperties.Description="Like"
SemanticProperties.Hint="Like this post."/>

<Label Text="2) Label with a semantic heading level:"/>
<Label Text="Installation" SemanticProperties.HeadingLevel="Level2" />

<Label AutomationId="TestStatus" Text="If this label appears, the test passed."/>
</VerticalStackLayout>
</ContentPage>
19 changes: 19 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31606.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading