【问题标题】:Messing with the AutomationId与 AutomationId 混淆
【发布时间】:2020-02-13 04:22:25
【问题描述】:

在 xamarin.forms 中设置堆栈布局的 AutomationId 以查找列表视图的元素是否安全? 原因: 我在列表视图中有一个组合框,它需要调用具有列表视图元素 id 的函数。 When the selection changed the method of the combo box is called, I check the automationId of the parent element of the combo box who's automationId I've set to a unique string from my collection which I can then identify and find where I am in the列表。

问题: 这样做安全吗?我是否违反了某些 Xamarin.Forms 规则或编程规则?

谢谢

【问题讨论】:

    标签: c# android ios xamarin.forms


    【解决方案1】:

    AFAIK 我不建议这样做,因为当自动化框架尝试搜索此元素时它可能会导致问题如果这就是您这样做的原因,请继续,否则不要。

    当您阅读AutomationId 的描述时,它会说:

    获取或设置一个允许自动化框架查找该元素并与之交互的值。

    自动化框架可用于查找此元素并与之交互的值。

    更多信息查看this Microsoft document

    我个人建议您做的不是将此值添加到您的 StackLayout 中,为什么不直接向您的 ComboBox 添加一个属性?喜欢标签或其他东西,然后通过检查该标签找到你的名字?

    【讨论】:

    • 你能举个例子吗?谢谢你的回答!
    • 期待什么样的例子?
    • 如何向我的 ComboBox 添加属性?
    猜你喜欢
    • 2014-07-09
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多