将AutomationID与ListView一起使用 [英] Using AutomationID with ListView
问题描述
我正在尝试将AutomationId附加到列表视图中的项目.理想情况下,将项目名称绑定到显示的项目.
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">
当我进入页面时,代码正在部署但未运行,是否有人找到了很好的解决方法来绑定ID?
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?
长期来看,我想将其与Xamarin Forms滚动功能一起使用,该功能可以滚动到标记的项目,但不能滚动到显示的文本.
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.
推荐答案
AutomationId
不是可绑定的属性,在Xamarin.Forms源代码中很明显:
AutomationId
is not a bindable property as apparent in the Xamarin.Forms source code:
string _automationId;
public string AutomationId
{
get { return _automationId; }
set
{
if (_automationId != null)
throw new InvalidOperationException("AutomationId may only be set one time");
_automationId = value;
}
}
一些人在与此同时,您需要对 AutomationId
进行硬编码,并牢记硬编码的id来构建UI测试.
You'll need to hard code the AutomationId
for the meantime and build your UI tests with a hard coded id in mind.
这篇关于将AutomationID与ListView一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!