diff options
author | Samantha Houts <samantha@teamredwall.com> | 2017-01-31 11:49:15 -0800 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 13:16:43 +0900 |
commit | 330f236a9e0c87b7e7ea2047e077b16df2e9b4d3 (patch) | |
tree | 4d33bfe5f705cdeb9b3c91f039805b976c35027f /Xamarin.Forms.Platform.WinRT/ViewRenderer.cs | |
parent | b362c49113b331280cc4f8c7e70fef3e52e07e37 (diff) | |
download | xamarin-forms-330f236a9e0c87b7e7ea2047e077b16df2e9b4d3.tar.gz xamarin-forms-330f236a9e0c87b7e7ea2047e077b16df2e9b4d3.tar.bz2 xamarin-forms-330f236a9e0c87b7e7ea2047e077b16df2e9b4d3.zip |
[All] Basic Accessibility Support (#713)
* [Core] Add accessibility properties
* [Controls] Add accessibility gallery
* [iOS] Implement accessibility properties
* [Android] Implement accessibilty properties
* [Win] Implement accessibility properties
* [Win] Select ListView item on selected for a11y
* Update docs
* TODO: macOS accessibility
* [iOS] Fix failing UI Tests
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/ViewRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/ViewRenderer.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs index 148da1b3..0017531f 100644 --- a/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/ViewRenderer.cs @@ -1,5 +1,6 @@ using Windows.UI.Xaml; using Windows.UI.Xaml.Automation; +using Windows.UI.Xaml.Automation.Peers; #if WINDOWS_UWP @@ -11,6 +12,11 @@ namespace Xamarin.Forms.Platform.WinRT { 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); @@ -33,5 +39,97 @@ namespace Xamarin.Forms.Platform.WinRT Control.SetValue(AutomationProperties.AutomationIdProperty, id); } } + protected override void SetAutomationPropertiesName() + { + if (Control == null) + { + base.SetAutomationPropertiesName(); + return; + } + + if (Element == null) + return; + + if (_defaultAutomationPropertiesName == null) + _defaultAutomationPropertiesName = (string)Control.GetValue(AutomationProperties.NameProperty); + + var elemValue = (string)Element.GetValue(Accessibility.NameProperty); + + if (!string.IsNullOrWhiteSpace(elemValue)) + Control.SetValue(AutomationProperties.NameProperty, elemValue); + else + Control.SetValue(AutomationProperties.NameProperty, _defaultAutomationPropertiesName); + } + + protected override void SetAutomationPropertiesAccessibilityView() + { + if (Control == null) + { + base.SetAutomationPropertiesAccessibilityView(); + return; + } + + if (Element == null) + return; + + if (!_defaultAutomationPropertiesAccessibilityView.HasValue) + _defaultAutomationPropertiesAccessibilityView = (AccessibilityView)Control.GetValue(AutomationProperties.AccessibilityViewProperty); + + var newValue = _defaultAutomationPropertiesAccessibilityView; + var elemValue = (bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty); + + if (elemValue == true) + newValue = AccessibilityView.Content; + else if (elemValue == false) + newValue = AccessibilityView.Raw; + + Control.SetValue(AutomationProperties.AccessibilityViewProperty, newValue); + } + + protected override void SetAutomationPropertiesHelpText() + { + if (Control == null) + { + base.SetAutomationPropertiesHelpText(); + return; + } + + if (Element == null) + return; + + if (_defaultAutomationPropertiesHelpText == null) + _defaultAutomationPropertiesHelpText = (string)Control.GetValue(AutomationProperties.HelpTextProperty); + + var elemValue = (string)Element.GetValue(Accessibility.HintProperty); + + if (!string.IsNullOrWhiteSpace(elemValue)) + Control.SetValue(AutomationProperties.HelpTextProperty, elemValue); + else + Control.SetValue(AutomationProperties.HelpTextProperty, _defaultAutomationPropertiesHelpText); + } + + protected override void SetAutomationPropertiesLabeledBy() + { + if (Control == null) + { + base.SetAutomationPropertiesLabeledBy(); + return; + } + + if (Element == null) + return; + + if (_defaultAutomationPropertiesLabeledBy == null) + _defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(AutomationProperties.LabeledByProperty); + + var elemValue = (VisualElement)Element.GetValue(Accessibility.LabeledByProperty); + var renderer = elemValue?.GetOrCreateRenderer(); + var nativeElement = renderer?.GetNativeElement(); + + if (nativeElement != null) + Control.SetValue(AutomationProperties.LabeledByProperty, nativeElement); + else + Control.SetValue(AutomationProperties.LabeledByProperty, _defaultAutomationPropertiesLabeledBy); + } } }
\ No newline at end of file |