private void SetAccessibilityTraits() { var baseElement = Element as MvvmAspire.Controls.Label; if (baseElement != null && baseElement.AccessibilityTraits != string.Empty) { var accessiblityTrait = baseElement.AccessibilityTraits; switch (accessiblityTrait) { case "button": base.Control.ContentDescription = base.Control.Text + " button. Double tap to activate."; break; //case "header": //base.Control.AccessibilityTraits = UIAccessibilityTrait.Header; break; case "tabs": AutomationProperties.SetIsInAccessibleTree(baseElement, true); AutomationProperties.SetName(baseElement, string.Concat(baseElement.Text, ". Tab.")); break; default: break; } } }
public MainPageCS() { var label = new Label { Text = "This is a label!", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; // Might have to add Internet permissions to Android project // ...Settings->Application-Permissions, in order to show the image var image = new Image { Source = "https://alexdunndev.files.wordpress.com/2017/02/xamarintips.png", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; var button = new Button { Text = "This is a button!", BorderWidth = 0.5, WidthRequest = 300, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; // Accessibility changes AutomationProperties.SetHelpText(image, "Images"); AutomationProperties.SetName(image, "Light bulb"); AutomationProperties.SetIsInAccessibleTree(button, true); Content = new StackLayout { Children = { label, image, button } }; }
public CustomContent(int idx) { AutomationProperties.SetIsInAccessibleTree(this, false); IsTabStop = false; Frame.IsTabStop = true; Frame.TabIndex = idx; var stack = new StackLayout(); var label = new Label() { Text = idx.ToString() }; Frame.Content = label; stack.Children.Add(Frame); AutomationProperties.SetHelpText(Frame, idx.ToString()); AutomationProperties.SetIsInAccessibleTree(label, false); AutomationProperties.SetIsInAccessibleTree(Frame, true); AutomationProperties.SetIsInAccessibleTree(stack, false); Content = stack; }
/// <summary> /// Enable accesibility /// </summary> /// <typeparam name="TView"></typeparam> /// <param name="view"></param> /// <param name="name"></param> /// <param name="helpText"></param> /// <param name="attributtedEnums"></param> /// <param name="isTabStop"></param> /// <param name="tabIndex"></param> /// <returns></returns> public static TView EnableAccessibility <TView>(this TView view, string name, string helpText, FieldAccessibilityType attributtedEnums = FieldAccessibilityType.None, bool?isTabStop = true, int?tabIndex = null) where TView : View { AutomationProperties.SetIsInAccessibleTree(view, true); AutomationProperties.SetName(view, name); AutomationProperties.SetHelpText(view, helpText); if (isTabStop.HasValue) { view.IsTabStop = isTabStop.Value; } if (tabIndex.HasValue) { view.TabIndex = tabIndex.Value; } #if __IOS__ if (attributtedEnums != FieldAccessibilityType.None) { var renderer = view.GetOrCreateRenderer(); if (renderer != null) { var nativeView = renderer.NativeView; var aeString = attributtedEnums.ToString(); var traitEnum = ParseEnum <UIAccessibilityTrait>(aeString); nativeView.AccessibilityTraits = traitEnum; } } #endif return(view); }
public MainPage() { InitializeComponent(); heading1 = new Label { Text = "Header 1", BackgroundColor = Color.GreenYellow, }; AutomationProperties.SetIsInAccessibleTree(heading1, true); text1 = new Label { Text = "Label 1 under header 1", BackgroundColor = Color.Orange, }; AutomationProperties.SetIsInAccessibleTree(text1, true); background.Children.Add(heading1); background.Children.Add(text1); heading2 = new Label { Text = "Header 2", BackgroundColor = Color.GreenYellow, }; AutomationProperties.SetIsInAccessibleTree(heading2, true); text2 = new Label { Text = "Label 2 under header 2", BackgroundColor = Color.Orange, }; AutomationProperties.SetIsInAccessibleTree(text2, true); background.Children.Add(heading2); background.Children.Add(text2); }
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs <Xamarin.Forms.Picker> e) { base.OnElementChanged(e); if (e.OldElement != null || this.Element == null) { return; } var element = Element as MvvmAspire.Controls.Picker; if (element != null) { SetTextColor(element); SetBorderColor(element); //var test = true; if (textColor.ToColor() != UIColor.White.ToColor()) { setPlaceHolderColor(element); } if (UIAccessibility.IsVoiceOverRunning) { AutomationProperties.SetIsInAccessibleTree(element, true); } //if( !test ) //setPlaceHolderColor(element); } }
private void hideFocus(object sender, EventArgs e) { b2.Text = "I am no more focusable"; AutomationProperties.SetIsInAccessibleTree(b2, false); AutomationProperties.SetIsInAccessibleTree(v1, false); v1.BackgroundColor = Color.Red; }
public async Task IsInAccessibleTree(bool result) { var button = new Button(); AutomationProperties.SetIsInAccessibleTree(button, result); var important = await GetValueAsync <bool, ButtonHandler>(button, handler => GetIsAccessibilityElement(handler)); Assert.Equal(result, important); }
Label CreateLabel(bool IsInAccessibleTree, string text) { Label label = new Label() { Text = text }; AutomationProperties.SetIsInAccessibleTree(label, IsInAccessibleTree); return(label); }
Entry CreateEntry(bool IsInAccessibleTree, string placeholderText) { Entry entry = new Entry() { Placeholder = placeholderText }; AutomationProperties.SetIsInAccessibleTree(entry, IsInAccessibleTree); return(entry); }
public MainPage() { InitializeComponent(); ICustomViewRenderer mybutton = new ICustomViewRenderer(); mybutton.Text = "TEST"; AutomationProperties.SetIsInAccessibleTree(mybutton, true); stacklayout.Children.Add(mybutton); }
/// <summary> /// Accessibility extension /// https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/accessibility/ /// </summary> /// <typeparam name="TView"></typeparam> /// <param name="view"></param> /// <param name="name"></param> /// <param name="helpText"></param> /// <param name="isTabStop"></param> /// <param name="tabIndex"></param> /// <returns></returns> public static TView SetAccessibility <TView>(this TView view, string name, string helpText, bool isTabStop = true, int?tabIndex = null) where TView : View { AutomationProperties.SetIsInAccessibleTree(view, true); AutomationProperties.SetName(view, name); AutomationProperties.SetHelpText(view, helpText); view.IsTabStop = isTabStop; if (tabIndex.HasValue) { view.TabIndex = tabIndex.Value; } return(view); }
private void groupAccessibleItems(Layout container) { String desc = ""; foreach (Label l in container.Children) { Console.WriteLine($"PIPPO: id={l.Text}"); AutomationProperties.SetIsInAccessibleTree(l, false); desc += l.Text; } Console.WriteLine($"PIPPO: totaldesc={desc}"); AutomationProperties.SetIsInAccessibleTree(container, true); AutomationProperties.SetName(container, desc); }
Label CreateLabel(bool?IsInAccessibleTree, string text) { Label label = new Label() { Text = text }; if (IsInAccessibleTree.HasValue) { AutomationProperties.SetIsInAccessibleTree(label, IsInAccessibleTree); } return(label); }
protected override void Init() { var stack = new StackLayout { AutomationId = "test", Children = { new Label { Text = "Turn on the Screen Reader. If you do not hear 'I am the StackLayout', this test has failed." } }, }; AutomationProperties.SetIsInAccessibleTree(stack, true); AutomationProperties.SetName(stack, "I am the StackLayout. This should be announced."); Content = stack; }
public MainPage() { InitializeComponent(); Label label = new Label { BackgroundColor = Color.Orange, }; AutomationProperties.SetIsInAccessibleTree(label, true); AutomationProperties.SetName(label, "Test accessibility name"); AbsoluteLayout.SetLayoutBounds(label, new Rectangle(0.5, 0.5, 0.3, 0.2)); AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.All); absolutelayout.Children.Add(label); }
public MainPage() { InitializeComponent(); accessibilityNameService = DependencyService.Get <IAccessibilityName>(DependencyFetchTarget.NewInstance); b1 = new Button { Text = "I HAVE AN ACCESSIBILITY DESCRIPTION", BackgroundColor = Color.Green, }; AutomationProperties.SetName(b1, "This is my accessibility name"); AutomationProperties.SetHelpText(b1, "And this is my accessibility help text"); stacklayout.Children.Add(b1); b2 = new Button { Text = "USELESS BUTTON WITH NO DESCRIPTION", BackgroundColor = Color.Green, }; stacklayout.Children.Add(b2); l1 = new Label { BackgroundColor = Color.Orange, WidthRequest = 100, HeightRequest = 100, }; AutomationProperties.SetIsInAccessibleTree(l1, true); AutomationProperties.SetName(l1, "Accessibility name should not be visible"); AutomationProperties.SetHelpText(l1, "Neither accessibility help text should not be visible"); stacklayout.Children.Add(l1); l2 = new Label { BackgroundColor = Color.Orange, WidthRequest = 100, HeightRequest = 100, }; AutomationProperties.SetIsInAccessibleTree(l2, true); stacklayout.Children.Add(l2); }
public MainPage() { InitializeComponent(); Title = "Xamarin accessibility events"; Button notAccessibleButton = new Button { Text = "Button 1", BackgroundColor = Color.LightGray, }; stacklayout.Children.Add(notAccessibleButton); IAccessibleButton accessibleButton = new IAccessibleButton { Text = "NOT IN FOCUS", TextColor = Color.Black, }; AutomationProperties.SetIsInAccessibleTree(accessibleButton, true); stacklayout.Children.Add(accessibleButton); }
void AddView(StackLayout layout, View view, string labelPrefix, string automationId, string buttonName = null, string buttonHelp = null) { var automationIdLabel = new Label(); automationIdLabel.Text = $"AutomationId = {automationId}"; automationIdLabel.AutomationId = $"{labelPrefix}-automationIdLabel"; var contentDescriptionLabel = new Label(); contentDescriptionLabel.AutomationId = $"{labelPrefix}-contentDescriptionLabel"; var nameAndHelpTextLabel = new Label(); nameAndHelpTextLabel.AutomationId = $"{labelPrefix}-nameAndHelpTextLabel"; view.AutomationId = automationId; view.Effects.Add(new ContentDescriptionEffect()); view.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { if (e.PropertyName == ContentDescriptionEffectProperties.ContentDescriptionProperty.PropertyName) { contentDescriptionLabel.Text = $"ContentDescription = {ContentDescriptionEffectProperties.GetContentDescription(view)}"; } if (e.PropertyName == ContentDescriptionEffectProperties.NameAndHelpTextProperty.PropertyName) { nameAndHelpTextLabel.Text = $"Name + HelpText = {ContentDescriptionEffectProperties.GetNameAndHelpText(view)}"; } }; layout.Children.Add(view); layout.Children.Add(automationIdLabel); layout.Children.Add(contentDescriptionLabel); layout.Children.Add(nameAndHelpTextLabel); AutomationProperties.SetIsInAccessibleTree(view, true); AutomationProperties.SetName(view, buttonName); AutomationProperties.SetHelpText(view, buttonHelp); }
// TODO: Instead of using hardcoded text for accessibility items, use a RESX file (same as you would for multiple languages) private void SetAccessibilityValues() { AutomationProperties.SetIsInAccessibleTree(textLabel, false); AutomationProperties.SetName(textLabel, "Text Label"); AutomationProperties.SetIsInAccessibleTree(textEntry, true); AutomationProperties.SetLabeledBy(textEntry, textLabel); // Redundant / Excess verbiage AutomationProperties.SetHelpText(textEntry, "My Text Entry"); AutomationProperties.SetIsInAccessibleTree(descriptionLabel, false); AutomationProperties.SetIsInAccessibleTree(descriptionEditor, true); AutomationProperties.SetLabeledBy(descriptionEditor, descriptionLabel); // Redundant / Excess verbiage AutomationProperties.SetHelpText(descriptionEditor, "My Description Editor"); AutomationProperties.SetIsInAccessibleTree(cancelButton, true); AutomationProperties.SetName(cancelButton, "Cancel"); AutomationProperties.SetIsInAccessibleTree(saveButton, true); AutomationProperties.SetName(saveButton, "Save"); if (Device.RuntimePlatform == Device.iOS) { AutomationProperties.SetHelpText(cancelButton, "Activate to cancel add new item."); AutomationProperties.SetHelpText(saveButton, "Activate to save new item."); } // TODO: Can also use data binding to set these values. set to values and remember to RaiseProperty changed when needed. //cancelButton.SetBinding(AutomationProperties.NameProperty, nameof(NewItem2ViewModel.CancelAutomationName)); //cancelButton.SetBinding(AutomationProperties.HelpTextProperty, nameof(NewItem2ViewModel.CancelAutomationHelptext)); //cancelButton.SetBinding(AutomationProperties.IsInAccessibleTreeProperty, nameof(NewItem2ViewModel.CancelIsInTree)); }
public MainPage() { InitializeComponent(); b1 = new Button { Text = "Press to hide BUTTON 2 focus", BackgroundColor = Color.Green, }; stacklayout.Children.Add(b1); b1.Clicked += hideFocus; b2 = new Button { Text = "BUTTON 2", BackgroundColor = Color.Green, }; stacklayout.Children.Add(b2); b3 = new Button { Text = "BUTTON 3", BackgroundColor = Color.Green, }; stacklayout.Children.Add(b3); v1 = new BoxView { BackgroundColor = Color.Green, WidthRequest = 100, HeightRequest = 50, }; AutomationProperties.SetIsInAccessibleTree(v1, true); AutomationProperties.SetName(v1, "Now I am accessible"); stacklayout.Children.Add(v1); }
public MainPage() { InitializeComponent(); background.Padding = 10; //container for the separated views separateElements = new StackLayout { BackgroundColor = Color.IndianRed, HeightRequest = 150, Padding = 10, }; background.Children.Add(separateElements); AutomationProperties.SetIsInAccessibleTree(separateElements, false); //here I create the single separated views sep1 = new Label { Text = "Separated label 1", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(sep1, true); sep2 = new Label { Text = "Separated label 2", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(sep2, true); sep3 = new Label { Text = "Separated label 3", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(sep3, true); separateElements.Children.Add(sep1); separateElements.Children.Add(sep2); separateElements.Children.Add(sep3); //container for the aggregated views aggregateElements = new StackLayout { BackgroundColor = Color.GreenYellow, HeightRequest = 150, Padding = 10, }; AutomationProperties.SetIsInAccessibleTree(aggregateElements, true); //the container that aggregates the views has to be accessible, setting his "AutomationProperties.IsInAccessibleTree" property to true if (Device.RuntimePlatform == Device.Android) { AutomationProperties.SetIsInAccessibleTree(aggregateElements, true); } background.Children.Add(aggregateElements); //here I create the single views to be aggregated into one single element //all the "Label" in Xamarin have "AutomationProperties.IsInAccessibleTree" property setted to false by default agg1 = new Label { Text = "Aggregated label 1", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(agg1, false); agg2 = new Label { Text = "Aggregated label 2", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(agg2, false); agg3 = new Label { Text = "Aggregated label 3", BackgroundColor = Color.Orange, HeightRequest = 40, }; AutomationProperties.SetIsInAccessibleTree(agg3, false); aggregateElements.Children.Add(agg1); aggregateElements.Children.Add(agg2); aggregateElements.Children.Add(agg3); }
public AccessibilityContentView() : base() { AutomationProperties.SetIsInAccessibleTree(this, true); }
public static TView DisableAccessibility <TView>(this TView view) where TView : View { AutomationProperties.SetIsInAccessibleTree(view, false); return(view); }
public static void AccessibilityEnabled <TView>(this TView view, bool enabled) where TView : View { AutomationProperties.SetIsInAccessibleTree(view, enabled); }
public AccessibilityPageCS() { var titleLabel = new Label { Text = "Accessibility Demo", HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; AutomationProperties.SetIsInAccessibleTree(titleLabel, true); AutomationProperties.SetName(titleLabel, "Title Label"); var messageLabel = new Label(); AutomationProperties.SetIsInAccessibleTree(messageLabel, true); AutomationProperties.SetName(messageLabel, "Instructions Label"); switch (Device.RuntimePlatform) { case Device.iOS: messageLabel.Text = "Use two fingers to swipe up or down the screen to read each element on the page."; break; case Device.Android: messageLabel.Text = "Quickly swipe right or left to navigate through elements on the page in sequence."; break; case Device.UWP: messageLabel.Text = "Use three fingers to swipe up the screen to read each element on the page."; break; } var activityIndicator = new ActivityIndicator(); AutomationProperties.SetIsInAccessibleTree(activityIndicator, true); AutomationProperties.SetName(activityIndicator, "Progress indicator"); var button = new Button { Text = "Toggle ActivityIndicator" }; AutomationProperties.SetIsInAccessibleTree(button, true); AutomationProperties.SetHelpText(button, "Tap to toggle the activity indicator"); button.Clicked += (sender, e) => { activityIndicator.IsRunning = !activityIndicator.IsRunning; AutomationProperties.SetHelpText(activityIndicator, activityIndicator.IsRunning ? "Running" : "Not running"); }; var stackLayout = new StackLayout { Orientation = StackOrientation.Horizontal }; var nameLabel = new Label { Text = "Enter your name: " }; var entry = new Entry { Placeholder = "Enter name here" }; AutomationProperties.SetIsInAccessibleTree(entry, true); AutomationProperties.SetLabeledBy(entry, nameLabel); stackLayout.Children.Add(nameLabel); stackLayout.Children.Add(entry); var imageLabel = new Label { Text = "Tap image to hear the alert box." }; AutomationProperties.SetIsInAccessibleTree(imageLabel, true); AutomationProperties.SetName(imageLabel, "Image Label"); var image = new Image { Source = "monkeyface.png" }; AutomationProperties.SetIsInAccessibleTree(image, true); AutomationProperties.SetName(image, "Monkey Face"); AutomationProperties.SetHelpText(image, "Tap to show an alert"); var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(sender, e) => await DisplayAlert("Success", "You tapped the image", "OK"); image.GestureRecognizers.Add(tapGestureRecognizer); Content = new ScrollView { Margin = new Thickness(20), Content = new StackLayout { Children = { titleLabel, messageLabel, button, activityIndicator, stackLayout, imageLabel, image } } }; }