如何使用AutomationProperties.Name? [英] How to use AutomationProperties.Name?

查看:425
本文介绍了如何使用AutomationProperties.Name?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请解释(最好用代码示例)如何AutomationProperties.Name属性编程和声明中使用使用XAML ?

Can anyone please explain (preferrably with a code example) how the AutomationProperties.Name property is used programmatically and declaratively with XAML?

说明

据我所知,编码的UI生成器在Visual Studio 2010举例来说,需要一个窗口的名称作为SearchProperty。

I understand that the Coded UI Builder in Visual Studio 2010, for instance, takes a Window's name as SearchProperty.

由于我的窗口的名称更改,我想有一个恒定的SearchProperty,我的编码的UI测试可以依靠。

Since my Window's name changes, I would like to have a constant SearchProperty that my Coded UI Tests can rely on.

在下面的代码示例中,我不想窗口标题是硬编码为管道1的性质,因为这改变了。

In the code example below, I don't want the window title to be hard-coded as "Properties of Pipe 1" since that changes.

代码示例

[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
}



链接

下面是一个例子:的如何:自动化开往WPF列表或组合框数据正常工作。我是不是能够适应它的窗口。

Here is an example: How To: Get automation working properly on data bound WPF list or combo box. I wasn't able to adapt it for a Window.

推荐答案

您可以改变附加属性的 AutomationProperties.Name 无论是在XAML:

You can change the attached property AutomationProperties.Name either in XAML using:

AutomationProperties.Name =新名字

AutomationProperties.Name = "new name"

或代码中使用:

Button.SetValue(AutomationProperties.NameProperty,新价值 );结果
或结果
AutomationProperties.SetName(按钮,新价值);

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

这篇关于如何使用AutomationProperties.Name?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆