public MainPage() { InitializeComponent(); background.Padding = 10; label1 = new Label { Text = "This label describes the next view", BackgroundColor = Color.GreenYellow, HeightRequest = 50, }; AutomationProperties.SetIsInAccessibleTree(label1, true); background.Children.Add(label1); entry1 = new Entry(); background.Children.Add(entry1); AutomationProperties.SetIsInAccessibleTree(entry1, true); //This work only for Android AutomationProperties.SetLabeledBy(entry1, label1); //the view "entry1" will be described by view "label1" //For iOS manually set the Accessibility Description of entry1 equal to the text of label1 if (Device.RuntimePlatform == Device.iOS) { AutomationProperties.SetName(entry1, label1.Text); } }
public FloatingLabelEntryXAML() { InitializeComponent(); input.Focused += Input_Focused; input.Unfocused += Input_Unfocused; AutomationProperties.SetLabeledBy(input, label); }
/// <summary> /// In some cases (just Popovers currently) we need to wait to set the automation properties until the element /// that needs them comes into existence (a PopoverRoot in the case of a Popover, when it's shown). This is /// used for that delayed initialization. /// </summary> /// <param name="element">UIElement on which to set the properties</param> public void InitAutomationProperties(UIElement element) { if (identifier != null) { AutomationProperties.SetAutomationId(element, identifier); } if (label != null) { AutomationProperties.SetName(element, label); } if (description != null) { AutomationProperties.SetHelpText(element, description); } if (labelWidget != null) { AutomationProperties.SetLabeledBy(element, (Toolkit.GetBackend(labelWidget) as WidgetBackend)?.Widget); } }
/// <inheritdoc /> protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (_dismissButton != null) { _dismissButton.Click -= DismissButton_Click; } if (_visualStateGroup != null) { _visualStateGroup.CurrentStateChanging -= OnCurrentStateChanging; _visualStateGroup.CurrentStateChanged -= OnCurrentStateChanged; } _dismissButton = (Button)GetTemplateChild(DismissButtonPart); _visualStateGroup = (VisualStateGroup)GetTemplateChild(GroupContent); _contentProvider = (ContentPresenter)GetTemplateChild(ContentPresenterPart); if (_dismissButton != null) { _dismissButton.Visibility = ShowDismissButton ? Visibility.Visible : Visibility.Collapsed; _dismissButton.Click += DismissButton_Click; AutomationProperties.SetName(_dismissButton, "WCT_InAppNotification_DismissButton_AutomationName".GetLocalized("Microsoft.Toolkit.Uwp.UI.Controls/Resources")); } if (_visualStateGroup != null) { _visualStateGroup.CurrentStateChanging += OnCurrentStateChanging; _visualStateGroup.CurrentStateChanged += OnCurrentStateChanged; } var firstNotification = _stackedNotificationOptions.FirstOrDefault(); if (firstNotification != null) { UpdateContent(firstNotification); VisualStateManager.GoToState(this, StateContentVisible, true); } AutomationProperties.SetLabeledBy(this, VisualTree.FindDescendant <ContentPresenter>(this)); }
/// <inheritdoc /> protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (_dismissButton != null) { _dismissButton.Click -= DismissButton_Click; } if (_visualStateGroup != null) { _visualStateGroup.CurrentStateChanging -= OnCurrentStateChanging; _visualStateGroup.CurrentStateChanged -= OnCurrentStateChanged; } _dismissButton = (Button)GetTemplateChild(DismissButtonPart); _visualStateGroup = (VisualStateGroup)GetTemplateChild(GroupContent); _contentProvider = (ContentPresenter)GetTemplateChild(ContentPresenterPart); if (_dismissButton != null) { _dismissButton.Visibility = ShowDismissButton ? Visibility.Visible : Visibility.Collapsed; _dismissButton.Click += DismissButton_Click; //AutomationProperties.SetName(_dismissButton, "Dismiss Notification"); } if (_visualStateGroup != null) { _visualStateGroup.CurrentStateChanging += OnCurrentStateChanging; _visualStateGroup.CurrentStateChanged += OnCurrentStateChanged; } var firstNotification = _stackedNotificationOptions.FirstOrDefault(); if (firstNotification != null) { UpdateContent(firstNotification); VisualStateManager.GoToState(this, StateContentVisible, true); } AutomationProperties.SetLabeledBy(this, this.GetFirstDescendantOfType <ContentPresenter>()); }
// 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)); }
private void InitializeComponents() { grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); entry = new Entry(); label = new Label() { Text = "PlaceHolder Text", InputTransparent = true, VerticalTextAlignment = TextAlignment.Center, }; grid.Children.Add(entry); grid.Children.Add(label); entry.Focused += Entry_Focused; entry.Unfocused += Entry_Unfocused; Content = grid; AutomationProperties.SetLabeledBy(entry, label); }
public ButtonGallery() { //ShellAppearance.SetNavBarVisible(this, false); Shell.SetSearchHandler(this, new SearchHandler() { SearchBoxVisibility = SearchBoxVisibility.Collapsible }); BackgroundColor = new Color(0.9f); var normal = new Button { Text = "Normal Button" }; normal.Effects.Add(Effect.Resolve($"{Issues.Effects.ResolutionGroupName}.BorderEffect")); var disabled = new Button { Text = "Disabled Button" }; var disabledswitch = new Switch(); disabledswitch.SetBinding(Switch.IsToggledProperty, "IsEnabled"); disabledswitch.BindingContext = disabled; var canTapLabel = new Label { Text = "Cannot Tap" }; disabled.Clicked += (sender, e) => { canTapLabel.Text = "TAPPED!"; }; var click = new Button { Text = "Click Button" }; var rotate = new Button { Text = "Rotate Button" }; var transparent = new Button { Text = "Transparent Button" }; string fontName; switch (Device.RuntimePlatform) { default: case Device.iOS: fontName = "Georgia"; break; case Device.Android: fontName = "sans-serif-light"; break; case Device.WinUI: fontName = "Comic Sans MS"; break; } var themedButton = new Button { Text = "Accent Button", //BackgroundColor = Colors.Accent, TextColor = Colors.White, ClassId = "AccentButton", FontFamily = fontName, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button), false) }; var borderButton = new Button { Text = "Border Button", BorderColor = Colors.Black, BackgroundColor = Colors.Purple, BorderWidth = 5, CornerRadius = 5 }; var timer = new Button { Text = "Timer" }; var busy = new Button { Text = "Toggle Busy" }; var alert = new Button { Text = "Alert" }; var alertSingle = new Button { Text = "Alert Single" }; var image = new Button { Text = "Image Button", ImageSource = new FileImageSource { File = "bank.png" }, BackgroundColor = Colors.Blue.WithLuminosity(.8f) }; AutomationProperties.SetName(image, "Image Automation Name"); var gif = new Button { ImageSource = "GifOne.gif" }; var automation = new Button { Text = "Display Name" }; AutomationProperties.SetName(automation, "Automation Name"); var labeledBy = new Button { Text = "Labeled By" }; var autoLabel = new Label { Text = "Label Text" }; AutomationProperties.SetLabeledBy(labeledBy, autoLabel); themedButton.Clicked += (sender, args) => { themedButton.FontFamily = Font.Default.Family; themedButton.FontSize = Font.Default.Size; }; alertSingle.Clicked += (sender, args) => DisplayAlert("Foo", "Bar", "Cancel"); disabled.IsEnabled = false; int i = 1; click.Clicked += (sender, e) => { click.Text = "Clicked " + i++; }; rotate.Clicked += (sender, e) => rotate.RelRotateTo(180); transparent.Opacity = .5; int j = 1; timer.Clicked += (sender, args) => Device.StartTimer(TimeSpan.FromSeconds(1), () => { timer.Text = "Timer Elapsed " + j++; return(j < 4); }); bool isBusy = false; busy.Clicked += (sender, args) => IsBusy = isBusy = !isBusy; alert.Clicked += async(sender, args) => { var result = await DisplayAlert("User Alert", "This is a user alert. This is only a user alert.", "Accept", "Cancel"); alert.Text = result ? "Accepted" : "Cancelled"; }; borderButton.Clicked += (sender, args) => borderButton.BackgroundColor = null; Content = new ScrollView { BackgroundColor = Colors.Red, Content = new StackLayout { Padding = new Size(20, 20), Children = { normal, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { disabled, disabledswitch, }, }, canTapLabel, click, rotate, transparent, themedButton, borderButton, new Button { Text = "Thin Border",BorderWidth = 1, BackgroundColor = Colors.White, BorderColor = Colors.Black, TextColor = Colors.Black }, new Button { Text = "Thinner Border",BorderWidth = .5, BackgroundColor = Colors.White, BorderColor = Colors.Black, TextColor = Colors.Black }, new Button { Text = "BorderWidth == 0",BorderWidth = 0, BackgroundColor = Colors.White, BorderColor = Colors.Black, TextColor = Colors.Black }, timer, busy, alert, alertSingle, image, gif, automation, autoLabel, labeledBy } } }; }
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 } } }; }