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

Obsolete some of the AutomationProperties #13104

Merged
merged 2 commits into from
Feb 14, 2023
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 @@ -92,6 +92,7 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e)

void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
{
SetContentDescription();
Expand All @@ -108,6 +109,7 @@ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
SetLabeledBy();
}
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ static string ConcatenateNameAndHint(Element Element)
{
string separator;

#pragma warning disable CS0618 // Type or member is obsolete
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
#pragma warning restore CS0618 // Type or member is obsolete

#pragma warning disable CS0618 // Type or member is obsolete
var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
#pragma warning restore CS0618 // Type or member is obsolete


if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))
Expand Down
17 changes: 17 additions & 0 deletions src/Controls/src/Core/AutomationProperties.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#nullable disable
using System;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="Type[@FullName='Microsoft.Maui.Controls.AutomationProperties']/Docs/*" />
public class AutomationProperties
{
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='HelpTextProperty']/Docs/*" />
[Obsolete("Use SemanticProperties.Hint instead. See the conceptual docs about accessibility for more information.")]
public static readonly BindableProperty HelpTextProperty = BindableProperty.Create("HelpText", typeof(string), typeof(AutomationProperties), default(string));

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='IsInAccessibleTreeProperty']/Docs/*" />
Expand All @@ -13,15 +16,19 @@ public class AutomationProperties
public static readonly BindableProperty ExcludedWithChildrenProperty = BindableProperty.Create("ExcludedWithChildren", typeof(bool?), typeof(AutomationProperties), null);

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='LabeledByProperty']/Docs/*" />
[Obsolete("Use a SemanticProperties.Description binding instead. See the conceptual docs about accessibility for more information.")]
public static readonly BindableProperty LabeledByProperty = BindableProperty.Create("LabeledBy", typeof(VisualElement), typeof(AutomationProperties), default(VisualElement));

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='NameProperty']/Docs/*" />
[Obsolete("Use SemanticProperties.Description instead. See the conceptual docs about accessibility for more information.")]
public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(AutomationProperties), default(string));

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='GetHelpText']/Docs/*" />
public static string GetHelpText(BindableObject bindable)
{
#pragma warning disable CS0618 // Type or member is obsolete
return (string)bindable.GetValue(HelpTextProperty);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='GetIsInAccessibleTree']/Docs/*" />
Expand All @@ -39,19 +46,25 @@ public static string GetHelpText(BindableObject bindable)
[System.ComponentModel.TypeConverter(typeof(ReferenceTypeConverter))]
public static VisualElement GetLabeledBy(BindableObject bindable)
{
#pragma warning disable CS0618 // Type or member is obsolete
return (VisualElement)bindable.GetValue(LabeledByProperty);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='GetName']/Docs/*" />
public static string GetName(BindableObject bindable)
{
#pragma warning disable CS0618 // Type or member is obsolete
return (string)bindable.GetValue(NameProperty);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='SetHelpText']/Docs/*" />
public static void SetHelpText(BindableObject bindable, string value)
{
#pragma warning disable CS0618 // Type or member is obsolete
bindable.SetValue(HelpTextProperty, value);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='SetIsInAccessibleTree']/Docs/*" />
Expand All @@ -68,13 +81,17 @@ public static void SetExcludedWithChildren(BindableObject bindable, bool? value)
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='SetLabeledBy']/Docs/*" />
public static void SetLabeledBy(BindableObject bindable, VisualElement value)
{
#pragma warning disable CS0618 // Type or member is obsolete
bindable.SetValue(LabeledByProperty, value);
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='SetName']/Docs/*" />
public static void SetName(BindableObject bindable, string value)
{
#pragma warning disable CS0618 // Type or member is obsolete
bindable.SetValue(NameProperty, value);
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell)
else
tableViewCell.AccessibilityElementsHidden = false;

#pragma warning disable CS0618 // Type or member is obsolete
if (cell.IsSet(AutomationProperties.NameProperty))
tableViewCell.AccessibilityLabel = cell.GetValue(AutomationProperties.NameProperty).ToString();
else
Expand All @@ -85,6 +86,8 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell)
tableViewCell.AccessibilityHint = cell.GetValue(AutomationProperties.HelpTextProperty).ToString();
else
tableViewCell.AccessibilityHint = null;
#pragma warning restore CS0618 // Type or member is obsolete

}

public virtual void SetBackgroundColor(UITableViewCell tableViewCell, Cell cell, UIColor color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ static void SetAccessibilityHint(UIBarButtonItem uIBarButtonItem, Element elemen
if (_defaultAccessibilityHint == null)
_defaultAccessibilityHint = uIBarButtonItem.AccessibilityHint;

#pragma warning disable CS0618 // Type or member is obsolete
uIBarButtonItem.AccessibilityHint = (string)element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint;
#pragma warning restore CS0618 // Type or member is obsolete
}

static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element element)
Expand All @@ -855,7 +857,9 @@ static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element eleme
if (_defaultAccessibilityLabel == null)
_defaultAccessibilityLabel = uIBarButtonItem.AccessibilityLabel;

#pragma warning disable CS0618 // Type or member is obsolete
uIBarButtonItem.AccessibilityLabel = (string)element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel;
#pragma warning restore CS0618 // Type or member is obsolete
}

static void SetIsAccessibilityElement(UIBarButtonItem uIBarButtonItem, Element element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public abstract partial class VisualElementRenderer<TElement> : IPlatformViewHan
[nameof(VisualElement.BackgroundColor)] = MapBackgroundColor,
[AutomationProperties.IsInAccessibleTreeProperty.PropertyName] = MapAutomationPropertiesIsInAccessibleTree,
#if WINDOWS
#pragma warning disable CS0618 // Type or member is obsolete
[AutomationProperties.NameProperty.PropertyName] = MapAutomationPropertiesName,
[AutomationProperties.HelpTextProperty.PropertyName] = MapAutomationPropertiesHelpText,
[AutomationProperties.LabeledByProperty.PropertyName] = MapAutomationPropertiesLabeledBy,
#pragma warning restore CS0618 // Type or member is obsolete
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public static string SetAccessibilityHint(this NativeView Control, Element Eleme
if (_defaultAccessibilityHint == null)
_defaultAccessibilityHint = Control.AccessibilityHint;

#pragma warning disable CS0618 // Type or member is obsolete
Control.AccessibilityHint = (string)Element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint;
#pragma warning restore CS0618 // Type or member is obsolete
#else
if (_defaultAccessibilityHint == null)
_defaultAccessibilityHint = Control.AccessibilityTitle;
Expand All @@ -52,7 +54,9 @@ public static string SetAccessibilityLabel(this NativeView Control, Element Elem
if (_defaultAccessibilityLabel == null)
_defaultAccessibilityLabel = Control.AccessibilityLabel;

#pragma warning disable CS0618 // Type or member is obsolete
Control.AccessibilityLabel = (string)Element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel;
#pragma warning restore CS0618 // Type or member is obsolete

return _defaultAccessibilityLabel;
}
Expand All @@ -66,7 +70,9 @@ public static string SetAccessibilityHint(this UIBarItem Control, Element Elemen
if (_defaultAccessibilityHint == null)
_defaultAccessibilityHint = Control.AccessibilityHint;

#pragma warning disable CS0618 // Type or member is obsolete
Control.AccessibilityHint = (string)Element.GetValue(AutomationProperties.HelpTextProperty) ?? _defaultAccessibilityHint;
#pragma warning restore CS0618 // Type or member is obsolete

return _defaultAccessibilityHint;

Expand All @@ -80,7 +86,9 @@ public static string SetAccessibilityLabel(this UIBarItem Control, Element Eleme
if (_defaultAccessibilityLabel == null)
_defaultAccessibilityLabel = Control.AccessibilityLabel;

#pragma warning disable CS0618 // Type or member is obsolete
Control.AccessibilityLabel = (string)Element.GetValue(AutomationProperties.NameProperty) ?? _defaultAccessibilityLabel;
#pragma warning restore CS0618 // Type or member is obsolete

return _defaultAccessibilityLabel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
UpdateTextAndStyle();
}
}
#pragma warning disable CS0618 // Type or member is obsolete
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
this.SetAccessibilityHint(_item);
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
this.SetAccessibilityLabel(_item);
#pragma warning restore CS0618 // Type or member is obsolete
}

void UpdateIconAndStyle()
Expand Down Expand Up @@ -149,9 +151,11 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
UpdateIcon();
else if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
UpdateIsEnabled();
#pragma warning disable CS0618 // Type or member is obsolete
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
this.SetAccessibilityHint(_item);
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
#pragma warning restore CS0618 // Type or member is obsolete
this.SetAccessibilityLabel(_item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ static string ConcatenateNameAndHint(Element Element)
{
string separator;

#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

if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))
separator = "";
Expand Down Expand Up @@ -166,7 +168,9 @@ internal static void SetLabeledBy(AView control, Element element)
if (element == null || control == null)
return;

#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

if (elemValue != null)
{
Expand Down Expand Up @@ -232,8 +236,10 @@ internal static void AccessibilitySettingsChanged(AView control, Element element

internal static string ConcatenateNameAndHelpText(BindableObject Element)
{
#pragma warning disable CS0618 // Type or member is obsolete
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
var helpText = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
#pragma warning restore CS0618 // Type or member is obsolete

if (string.IsNullOrWhiteSpace(name))
return helpText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public static string SetAutomationPropertiesName(this FrameworkElement Control,
if (_defaultAutomationPropertiesName == null)
_defaultAutomationPropertiesName = (string)Control.GetValue(NativeAutomationProperties.NameProperty);

#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

if (!string.IsNullOrWhiteSpace(elemValue))
Control.SetValue(NativeAutomationProperties.NameProperty, elemValue);
Expand Down Expand Up @@ -60,7 +62,9 @@ public static string SetAutomationPropertiesHelpText(this FrameworkElement Contr
if (_defaultAutomationPropertiesHelpText == null)
_defaultAutomationPropertiesHelpText = (string)Control.GetValue(NativeAutomationProperties.HelpTextProperty);

#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

if (!string.IsNullOrWhiteSpace(elemValue))
Control.SetValue(NativeAutomationProperties.HelpTextProperty, elemValue);
Expand All @@ -85,16 +89,18 @@ public static UIElement SetAutomationPropertiesLabeledBy(

if (_defaultAutomationPropertiesLabeledBy == null)
_defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty);

#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)
nativeElement = (elemValue as IView)?.ToHandler(mauiContext)?.PlatformView as FrameworkElement;

if (nativeElement != null)
#pragma warning disable CS0618 // Type or member is obsolete
Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement);
#pragma warning restore CS0618 // Type or member is obsolete
else
Control.SetValue(NativeAutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy);

Expand All @@ -117,10 +123,11 @@ static string ConcatenateNameAndHint(Element Element)
{
string separator;

#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

if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))
separator = "";
Expand Down
2 changes: 2 additions & 0 deletions src/Controls/src/Core/SemanticProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public static void SetHeadingLevel(BindableObject bindable, SemanticHeadingLevel
SemanticProperties.DescriptionProperty,
SemanticProperties.HintProperty,
SemanticProperties.HeadingLevelProperty,
#pragma warning disable CS0618 // Type or member is obsolete
AutomationProperties.NameProperty,
AutomationProperties.LabeledByProperty,
AutomationProperties.HelpTextProperty,
#pragma warning restore CS0618 // Type or member is obsolete
AutomationProperties.IsInAccessibleTreeProperty,
};

Expand Down