Skip to content

Commit 9c10d1a

Browse files
jfversluisTJ Lambert
authored andcommitted
Obsolete some of the AutomationProperties (dotnet#13104)
* Obsolete some of the AutomationProperties * Update SemanticProperties.cs
1 parent c42aca6 commit 9c10d1a

File tree

11 files changed

+62
-3
lines changed

11 files changed

+62
-3
lines changed

src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e)
9292

9393
void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
9494
{
95+
#pragma warning disable CS0618 // Type or member is obsolete
9596
if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
9697
{
9798
SetContentDescription();
@@ -108,6 +109,7 @@ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
108109
{
109110
SetLabeledBy();
110111
}
112+
#pragma warning restore CS0618 // Type or member is obsolete
111113
}
112114
}
113115
}

src/Compatibility/Core/src/Windows/AccessibilityExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ static string ConcatenateNameAndHint(Element Element)
2222
{
2323
string separator;
2424

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

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

2933

3034
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))

src/Controls/src/Core/AutomationProperties.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#nullable disable
2+
using System;
3+
24
namespace Microsoft.Maui.Controls
35
{
46
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="Type[@FullName='Microsoft.Maui.Controls.AutomationProperties']/Docs/*" />
57
public class AutomationProperties
68
{
79
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='HelpTextProperty']/Docs/*" />
10+
[Obsolete("Use SemanticProperties.Hint instead. See the conceptual docs about accessibility for more information.")]
811
public static readonly BindableProperty HelpTextProperty = BindableProperty.Create("HelpText", typeof(string), typeof(AutomationProperties), default(string));
912

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

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

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

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

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

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

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

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

7489
/// <include file="../../docs/Microsoft.Maui.Controls/AutomationProperties.xml" path="//Member[@MemberName='SetName']/Docs/*" />
7590
public static void SetName(BindableObject bindable, string value)
7691
{
92+
#pragma warning disable CS0618 // Type or member is obsolete
7793
bindable.SetValue(NameProperty, value);
94+
#pragma warning restore CS0618 // Type or member is obsolete
7895
}
7996
}
8097
}

src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell)
7676
else
7777
tableViewCell.AccessibilityElementsHidden = false;
7878

79+
#pragma warning disable CS0618 // Type or member is obsolete
7980
if (cell.IsSet(AutomationProperties.NameProperty))
8081
tableViewCell.AccessibilityLabel = cell.GetValue(AutomationProperties.NameProperty).ToString();
8182
else
@@ -85,6 +86,8 @@ public virtual void SetAccessibility(UITableViewCell tableViewCell, Cell cell)
8586
tableViewCell.AccessibilityHint = cell.GetValue(AutomationProperties.HelpTextProperty).ToString();
8687
else
8788
tableViewCell.AccessibilityHint = null;
89+
#pragma warning restore CS0618 // Type or member is obsolete
90+
8891
}
8992

9093
public virtual void SetBackgroundColor(UITableViewCell tableViewCell, Cell cell, UIColor color)

src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,9 @@ static void SetAccessibilityHint(UIBarButtonItem uIBarButtonItem, Element elemen
861861
if (_defaultAccessibilityHint == null)
862862
_defaultAccessibilityHint = uIBarButtonItem.AccessibilityHint;
863863

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

867869
static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element element)
@@ -872,7 +874,9 @@ static void SetAccessibilityLabel(UIBarButtonItem uIBarButtonItem, Element eleme
872874
if (_defaultAccessibilityLabel == null)
873875
_defaultAccessibilityLabel = uIBarButtonItem.AccessibilityLabel;
874876

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

878882
static void SetIsAccessibilityElement(UIBarButtonItem uIBarButtonItem, Element element)

src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ public abstract partial class VisualElementRenderer<TElement> : IPlatformViewHan
3535
[nameof(VisualElement.BackgroundColor)] = MapBackgroundColor,
3636
[AutomationProperties.IsInAccessibleTreeProperty.PropertyName] = MapAutomationPropertiesIsInAccessibleTree,
3737
#if WINDOWS
38+
#pragma warning disable CS0618 // Type or member is obsolete
3839
[AutomationProperties.NameProperty.PropertyName] = MapAutomationPropertiesName,
3940
[AutomationProperties.HelpTextProperty.PropertyName] = MapAutomationPropertiesHelpText,
4041
[AutomationProperties.LabeledByProperty.PropertyName] = MapAutomationPropertiesLabeledBy,
42+
#pragma warning restore CS0618 // Type or member is obsolete
4143
#endif
4244
};
4345

src/Controls/src/Core/Compatibility/iOS/Extensions/AccessibilityExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public static string SetAccessibilityHint(this NativeView Control, Element Eleme
3333
if (_defaultAccessibilityHint == null)
3434
_defaultAccessibilityHint = Control.AccessibilityHint;
3535

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

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

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

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

7177
return _defaultAccessibilityHint;
7278

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

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

8593
return _defaultAccessibilityLabel;
8694
}

src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
7575
UpdateTextAndStyle();
7676
}
7777
}
78+
#pragma warning disable CS0618 // Type or member is obsolete
7879
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
7980
this.SetAccessibilityHint(_item);
8081
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
8182
this.SetAccessibilityLabel(_item);
83+
#pragma warning restore CS0618 // Type or member is obsolete
8284
}
8385

8486
void UpdateIconAndStyle()
@@ -149,9 +151,11 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
149151
UpdateIcon();
150152
else if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName)
151153
UpdateIsEnabled();
154+
#pragma warning disable CS0618 // Type or member is obsolete
152155
else if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
153156
this.SetAccessibilityHint(_item);
154157
else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
158+
#pragma warning restore CS0618 // Type or member is obsolete
155159
this.SetAccessibilityLabel(_item);
156160
}
157161

src/Controls/src/Core/Platform/Android/AutomationPropertiesProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ static string ConcatenateNameAndHint(Element Element)
7979
{
8080
string separator;
8181

82+
#pragma warning disable CS0618 // Type or member is obsolete
8283
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
8384
var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
85+
#pragma warning restore CS0618 // Type or member is obsolete
8486

8587
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))
8688
separator = "";
@@ -166,7 +168,9 @@ internal static void SetLabeledBy(AView control, Element element)
166168
if (element == null || control == null)
167169
return;
168170

171+
#pragma warning disable CS0618 // Type or member is obsolete
169172
var elemValue = (VisualElement)element.GetValue(AutomationProperties.LabeledByProperty);
173+
#pragma warning restore CS0618 // Type or member is obsolete
170174

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

233237
internal static string ConcatenateNameAndHelpText(BindableObject Element)
234238
{
239+
#pragma warning disable CS0618 // Type or member is obsolete
235240
var name = (string)Element.GetValue(AutomationProperties.NameProperty);
236241
var helpText = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
242+
#pragma warning restore CS0618 // Type or member is obsolete
237243

238244
if (string.IsNullOrWhiteSpace(name))
239245
return helpText;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public static string SetAutomationPropertiesName(this FrameworkElement Control,
2020
if (_defaultAutomationPropertiesName == null)
2121
_defaultAutomationPropertiesName = (string)Control.GetValue(NativeAutomationProperties.NameProperty);
2222

23+
#pragma warning disable CS0618 // Type or member is obsolete
2324
var elemValue = (string)Element.GetValue(AutomationProperties.NameProperty);
25+
#pragma warning restore CS0618 // Type or member is obsolete
2426

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

65+
#pragma warning disable CS0618 // Type or member is obsolete
6366
var elemValue = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
67+
#pragma warning restore CS0618 // Type or member is obsolete
6468

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

8690
if (_defaultAutomationPropertiesLabeledBy == null)
8791
_defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty);
88-
92+
#pragma warning disable CS0618 // Type or member is obsolete
8993
var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty);
90-
94+
#pragma warning restore CS0618 // Type or member is obsolete
9195
FrameworkElement nativeElement = null;
9296

9397
if (mauiContext != null)
9498
nativeElement = (elemValue as IView)?.ToHandler(mauiContext)?.PlatformView as FrameworkElement;
9599

96100
if (nativeElement != null)
101+
#pragma warning disable CS0618 // Type or member is obsolete
97102
Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement);
103+
#pragma warning restore CS0618 // Type or member is obsolete
98104
else
99105
Control.SetValue(NativeAutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy);
100106

@@ -117,10 +123,11 @@ static string ConcatenateNameAndHint(Element Element)
117123
{
118124
string separator;
119125

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

122129
var hint = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
123-
130+
#pragma warning restore CS0618 // Type or member is obsolete
124131

125132
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(hint))
126133
separator = "";

0 commit comments

Comments
 (0)