forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewRenderer.cs
134 lines (109 loc) · 4.2 KB
/
ViewRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
namespace Xamarin.Forms.Platform.UWP
{
public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement, TNativeElement> where TElement : View where TNativeElement : FrameworkElement
{
string _defaultAutomationPropertiesName;
AccessibilityView? _defaultAutomationPropertiesAccessibilityView;
string _defaultAutomationPropertiesHelpText;
UIElement _defaultAutomationPropertiesLabeledBy;
protected override void OnElementChanged(ElementChangedEventArgs<TElement> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
UpdateBackgroundColor();
UpdateFlowDirection();
}
}
protected override void SetAutomationId(string id)
{
if (Control == null)
{
base.SetAutomationId(id);
}
else
{
SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, $"{id}_Container");
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, id);
}
}
protected override void SetAutomationPropertiesName()
{
if (Control == null)
{
base.SetAutomationPropertiesName();
return;
}
if (Element == null)
return;
if (_defaultAutomationPropertiesName == null)
_defaultAutomationPropertiesName = (string)Control.GetValue(Windows.UI.Xaml.Automation.AutomationProperties.NameProperty);
var elemValue = (string)Element.GetValue(AutomationProperties.NameProperty);
if (!string.IsNullOrWhiteSpace(elemValue))
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.NameProperty, elemValue);
else
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.NameProperty, _defaultAutomationPropertiesName);
}
protected override void SetAutomationPropertiesAccessibilityView()
{
if (Control == null)
{
base.SetAutomationPropertiesAccessibilityView();
return;
}
if (Element == null)
return;
if (!_defaultAutomationPropertiesAccessibilityView.HasValue)
_defaultAutomationPropertiesAccessibilityView = (AccessibilityView)Control.GetValue(Windows.UI.Xaml.Automation.AutomationProperties.AccessibilityViewProperty);
var newValue = _defaultAutomationPropertiesAccessibilityView;
var elemValue = (bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty);
if (elemValue == true)
newValue = AccessibilityView.Content;
else if (elemValue == false)
newValue = AccessibilityView.Raw;
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AccessibilityViewProperty, newValue);
}
protected override void SetAutomationPropertiesHelpText()
{
if (Control == null)
{
base.SetAutomationPropertiesHelpText();
return;
}
if (Element == null)
return;
if (_defaultAutomationPropertiesHelpText == null)
_defaultAutomationPropertiesHelpText = (string)Control.GetValue(Windows.UI.Xaml.Automation.AutomationProperties.HelpTextProperty);
var elemValue = (string)Element.GetValue(AutomationProperties.HelpTextProperty);
if (!string.IsNullOrWhiteSpace(elemValue))
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.HelpTextProperty, elemValue);
else
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.HelpTextProperty, _defaultAutomationPropertiesHelpText);
}
protected override void SetAutomationPropertiesLabeledBy()
{
if (Control == null)
{
base.SetAutomationPropertiesLabeledBy();
return;
}
if (Element == null)
return;
if (_defaultAutomationPropertiesLabeledBy == null)
_defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty);
var elemValue = (VisualElement)Element.GetValue(AutomationProperties.LabeledByProperty);
var renderer = elemValue?.GetOrCreateRenderer();
var nativeElement = renderer?.GetNativeElement();
if (nativeElement != null)
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty, nativeElement);
else
Control.SetValue(Windows.UI.Xaml.Automation.AutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy);
}
void UpdateFlowDirection()
{
Control.UpdateFlowDirection(Element);
}
}
}