Forum Xamarin.Forms

Use Accessibility in Listview and CarouselView Xamarin.Forms

Do anyone have any sample regarding accessibility for ListView and CarouselView in Xamarin.Forms? I am not able to find anywhere any sample for that In official documentation they have simply used for Label and Entry.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    The ListView control has built-in AutomationId for all their inner elements. To keep unique AutomationId, these inner element’s AutomationIds are updated based on ListView control AutomationId.

    We can creating binding on AutomationId of the inner element and get the AutomationId of the items by tapping it .

     <ListView x:Name="listView" ItemsSource="{Binding contactsinfo}" >
        <ListView.ItemTemplate >
            <DataTemplate>
                <Grid x:Name="grid" AutomationId="{Binding AutomationID}">
                    <Grid.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding Source={x:Reference listView}, Path=BindingContext.TapCommand}" CommandParameter="{Binding .}"/>
                    </Grid.GestureRecognizers>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    
    public class ContactsViewModel : INotifyPropertyChanged
    {
        public Command<object> TapCommand { get; set; }
        public ObservableCollection<Contacts> contactsinfo { get; set; }
    
        public ContactsViewModel()
        {
            contactsinfo = new ObservableCollection<Contacts>();
            TapCommand = new Command<object>(OnTapped);
            GenerateInfo();
        }
    
        private void OnTapped(object obj)
        {
            var item = obj as Contacts;
            App.Current.MainPage.DisplayAlert("Item tapped", "Automation ID is " + item.AutomationID, "Ok");
        }
    
        public void GenerateInfo()
        {
            Random r = new Random();
            for (int i = 0; i < 50; i++)
            {
                var contact = new Contacts(CustomerNames[i], r.Next(720, 799).ToString() + " - " + r.Next(3010, 3999).ToString());
                contact.ContactImage = ImageSource.FromResource("ListViewXamarin.Images.Image" + r.Next(0, 28) + ".png");
                contact.AutomationID = "Automation" + CustomerNames[i];
                contactsinfo.Add(contact);
            }
        }
    }
    
    

  • JohnHardmanJohnHardman GBUniversity admin
    edited October 2020

    @saurav_kumar said:
    Do anyone have any sample regarding accessibility for ListView and CarouselView in Xamarin.Forms? I am not able to find anywhere any sample for that In official documentation they have simply used for Label and Entry.

    I'm not aware of an official Xamarin.Forms sample that shows AutomationProperties being used for all of (or even most of) the built-in Xamarin.Forms View types. It's something that is clearly needed, as there are still a lot of issues around accessibility using Xamarin.Forms out of the box. GitHub contains a number of issues at https://github.com/xamarin/Xamarin.Forms/issues?q=is:issue+is:open+accessibility , but I'm sure there are more that haven't been logged yet. I'm working on accessibility in my codebase at the moment and suspect I'll be logging some problems when I have time.

    @DavidBritch - Are there plans to add a sample showing AutomationProperties, TabIndex, AccessKeys etc being used for all (where appropriate) of the built-in Xamarin.Forms View types, including containers/layouts such as ListView, ScrollView, CarouselView etc.? If a sample could also show how to handle things such as layout changes in a cross-platform manner that would be great.

    @DavidOrtinau @JamesMontemagno - I'm hoping that in Maui, MinimumHeightRequest and MinimumWidthRequest will do what people expect, so that for visually impaired, people with mobility or motor skills impairments, etc., buttons can be guaranteed to be at least a certain size) - any idea if that will be happening?

  • DavidBritchDavidBritch GBXamarin Team Xamurai

    @JohnHardman Afraid there are no plans to do that, at the moment. It'd first require engineering to make more of an investment in this area.

  • JohnHardmanJohnHardman GBUniversity admin

    @DavidBritch said:
    @JohnHardman Afraid there are no plans to do that, at the moment. It'd first require engineering to make more of an investment in this area.

    In terms of the sample, or the accessibility support in XF/Maui itself? Who's the person to follow up with re. the investment?

  • DavidBritchDavidBritch GBXamarin Team Xamurai

    @JohnHardman In terms of accessibility support in XF/Maui. For example, I've noticed that as new controls are added they often lack full accessibility support. That's one to follow up with David Ortinau.

  • JohnHardmanJohnHardman GBUniversity admin

    Thanks @DavidBritch

Sign In or Register to comment.