AutomationProperties.Name VS X:名称 [英] AutomationProperties.Name VS x:Name

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

问题描述

没有为之间的 AutomationProperties.Name X上的codedUI测试生成器没有什么区别:名称。但是第一个可以覆盖第二个。 另外,AtomationProperties.Name支持数据绑定, X:名称当然,这并不

There is no difference for the "CodedUI test builder" between the AutomationProperties.Name and x:Name. But the first one can override the second one. Also the AtomationProperties.Name supports data binding, x:Name of course doesn't.

<一个href="http://10rem.net/blog/2010/07/02/silverlight-wpf-dont-name-elements-unless-you-have-to-why-xnaming-everything-is-bad"相对=nofollow>据我们所知如果你使用MVVM模式,最好是只使用 X:名称在需要时

As we know if you are using the MVVM pattern it is best to only use x:Name when needed.

所以应该 AutomationProperties.Name 是pferred至$ P $ X:?名称

So should AutomationProperties.Name be preferred to x:Name?

推荐答案

X:名称 AutomationProperties.Name 是两个完全不同的东西,所以这个问题:我应该用一个或其他是基于一个错误的premise:在一般情况下,你的不能的使用一个或另一个

Summary

x:Name and AutomationProperties.Name are two totally different things, so the question "should I use one or the other" is based on a false premise: in general, you cannot use one or the other.

X中的用途:名称是要找出一个WPF控制在code-后面,这样开发人员可以访问它。它是没有意义的(或唯一的)之类的范围之外建模特定WPF元素

The purpose of x:Name is to identify a WPF control in code-behind so that the developer can access it. It is not meaningful (or unique) outside the scope of the class that models a specific WPF element.

在另一方面,目的 AutomationProperties.Name 是识别在对话或其它类型的窗口即$ P $的上下文中一个用户接口元件psented为交互的用户。具体而言,其值应符合哪些用户会感觉到作为用户界面元素的标签(这样如一个辅助工具可以告知元素的用途的用户)。

On the other hand, the purpose of AutomationProperties.Name is to identify a user interface element in the context of a dialog or other type of window that is presented to the user for interaction. Specifically, its value should match what a user would perceive as the "label" of that user interface element (so that e.g. an accessibility tool can inform the user of the purpose of the element).

在任何工具(如XAML编译器)可以选择使用 x的值:名称 AutomationProperties.Name 以及并不意味着它的东西,你应该做的; IMHO这正是方便,其导致的问题,因为这两者之间的区别是从显影剂隐藏的,所以总是一个或其他属性最终会具有语义错误的值的类型。

While any tool (such as a XAML compiler) can choose to use the value of x:Name for AutomationProperties.Name as well doesn't mean that it's something you should do; IMHO this is exactly the type of "convenience" that results in problems because the difference between the two is hidden from the developer, so invariably one or the other property would end up having a semantically wrong value.

在每个属性的语义和技术方面的信息在之后的部分。

Information on the semantic and technical aspects of each of the property follows in the next sections.

借助 MSDN文档页解释说,

十大之后:名称被应用到一个框架的依托编程模型,   名称是相当于保存一个对象引用的变量   或实例作为一个构造函数返回。

After x:Name is applied to a framework's backing programming model, the name is equivalent to the variable that holds an object reference or an instance as returned by a constructor.

这是x的值:名称指令的使用必须是XAML中是唯一的   名称范围。

The value of an x:Name directive usage must be unique within a XAML namescope.

[...]

在标准构建配置为使用WPF应用程序   XAML,部分类和code-背后,指定x:名称变   现场的是底层code创建时的XAML名称   由标记编译生成任务处理,而那场举行   引用的对象。

Under the standard build configuration for a WPF application that uses XAML, partial classes, and code-behind, the specified x:Name becomes the name of a field that is created in the underlying code when XAML is processed by a markup compilation build task, and that field holds a reference to the object.

从上面我们可以告诉大家, X:名称

From the above we can tell that x:Name:

  1. 用于访问该元件在code(未XAML),因为它控制该保持元件的字段的名称
  2. 必须在一个独特的XAML名称(因为你不能有相同的两个领域在code名称)
  1. is used to access the element in code (not XAML), since it controls the name of the field that holds the element
  2. must be unique within a XAML namescope (since you cannot have two fields with the same name in code)

解释 WPF访问文档

AutomationProperties.Name

The WPF accessibility documentation explains that

有关自动化元素的名称是由开发商指定的。该   Name属性应始终与标签上的文字是一致   屏幕。例如,该名称必须是浏览...的按钮元素   与浏览...作为标签。

The Name for an automation element is assigned by the developer. The Name property should always be consistent with the label text on screen. For example, the Name must be "Browse…" for the button element with "Browse…" as the label.

这篇关于AutomationProperties.Name VS X:名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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