将AutomationID与ListView一起使用

The*_*oid 5 c# android listview xamarin

我正在尝试将automationId附加到listview中的项目.理想情况下,通过将项目名称绑定到显示的项目.

<ListView
ItemsSource="{Binding Projects}"
AutomationId="{Binding Projects}
HasUnevenRows="True"
IsPullToRefreshEnabled="true"
CachingStrategy="RecycleElement"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">  
Run Code Online (Sandbox Code Playgroud)

当我到达页面时,代码正在部署但没有运行,是否有人找到了一个很好的解决方法来绑定ID?

从长远来看,我希望将它与Xamarin Forms能力一起使用,滚动可以滚动到标记的项目,但不滚动到显示的文本.

mat*_*dev 4

AutomationId不是 Xamarin.Forms 源代码中明显的可绑定属性:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

一些人在Xamarins User Voice上提出了这一问题。

AutomationId同时,您需要对其进行硬编码,并在构建 UI 测试时考虑硬编码的 id。