Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AutomationID with ListView

I'm trying to attach an automationId to items within a listview. Ideally by binding a project name to the item that is shown.

<ListView
ItemsSource="{Binding Projects}"
AutomationId="{Binding Projects}
HasUnevenRows="True"
IsPullToRefreshEnabled="true"
CachingStrategy="RecycleElement"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">  

The code is deploying but not running when I get to the page, has anyone found a good workaround to bind the ID like that?

Long term, I want to use it with the Xamarin Forms ability to scroll which can scroll to a marked item, but not scroll to a displayed text.

like image 487
TheSamDroid Avatar asked Jan 11 '17 15:01

TheSamDroid


1 Answers

AutomationId is not a bindable property as apparent in the Xamarin.Forms source code:

Xamarin.Forms.Core.Element.cs

string _automationId;


public string AutomationId
{
    get { return _automationId; }
    set
    {
        if (_automationId != null)
            throw new InvalidOperationException("AutomationId may only be set one time");
        _automationId = value;
    }
}

This has been raised by several people on Xamarins User Voice.

You'll need to hard code the AutomationId for the meantime and build your UI tests with a hard coded id in mind.

like image 87
matthewrdev Avatar answered Oct 04 '22 03:10

matthewrdev