gpt4 book ai didi

c# - 如何使用 AutomationProperties.Name?

转载 作者:可可西里 更新时间:2023-11-01 08:43:56 24 4
gpt4 key购买 nike

问题

任何人都可以解释(最好使用代码示例)AutomationProperties.Name 属性如何以编程方式和声明方式与 XAML 一起使用吗?

解释

我了解到,例如,Visual Studio 2010 中的编码 UI 生成器将窗口的名称作为 SearchProperty。

由于我的窗口名称发生变化,我希望有一个常量 SearchProperty,我的编码 UI 测试可以依赖它。

在下面的代码示例中,我不希望窗口标题被硬编码为“管道 1 的属性”,因为它发生了变化。

代码示例

[GeneratedCode("Coded UITest Builder", "10.0.30319.1")]
public class UIListViewPropertiesTable1 : WpfTable
{

public UIListViewPropertiesTable1(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WpfTable.PropertyNames.AutomationId] = "listViewProperties";
this.WindowTitles.Add("Properties of Pipe 1");
#endregion
}

#region Properties
public WpfText NameOfComponent
{
get
{
if ((this.mNameOfComponent == null))
{
this.mNameOfComponent = new WpfText(this);
#region Search Criteria
this.mNameOfComponent.SearchProperties[WpfText.PropertyNames.Name] = "Pipe 1";
this.mNameOfComponent.WindowTitles.Add("Properties of Pipe 1");
#endregion
}
return this.mNameOfComponent;
}
}
#endregion

#region Fields
private WpfText mNameOfComponent;
#endregion
}

链接

这是一个例子:How To: Get automation working properly on data bound WPF list or combo box .我无法针对 Window 进行调整。

最佳答案

您可以在 XAML 中使用以下方法更改附加属性 AutomationProperties.Name:

AutomationProperties.Name = "new name"

或在代码中使用:

Button.SetValue(AutomationProperties.NameProperty, "new value");
or
AutomationProperties.SetName(Button, "new value");

关于c# - 如何使用 AutomationProperties.Name?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2920062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com