绑定路径中的括号是什么意思?

时间:2022-11-27 22:34:13

Recently i've read 'Databinding overview' article at MSDN and there is such sample code:

最近我在MSDN上阅读了“数据绑定概述”一文,有以下示例代码:

<TextBox.ToolTip>
  <Binding RelativeSource="{RelativeSource Self}" Path="(Validation.Errors)[0].ErrorContent"/>
</TextBox.ToolTip>

I know that {} means markup extensions but what mean () parentheses here? It would be nice someone share link to explanation such syntax. Thanks!

我知道{}意味着标记扩展,但这里的括号是什么意思?有人会分享链接到解释这样的语法会很好。谢谢!

Path="(Validation.Errors)[0].ErrorContent"

4 个解决方案

#1


11  

The () parentheses refer to Attached Properties.

()括号引用附加属性。

Binding to an Attached Property

绑定附属物

#2


4  

Quoting the MSDN library (I'm quoting MSDN here because I couldn't have written it down better):

引用MSDN库(我在这里引用MSDN,因为我无法将其写得更好):

This syntax is generally used for one of the following cases:

此语法通常用于以下情况之一:

  • The path is specified in XAML that is in a style or template that does not have a specified TargetType. A qualified usage is generally not valid for cases other than this, because in non-style, non-template cases, the property exists on an instance, not a type.
  • 路径在XAML中指定,该路径位于没有指定TargetType的样式或模板中。合格用法通常对除此之外的其他情况无效,因为在非样式的非模板情况下,该属性存在于实例上,而不是类型。
  • The property is an attached property.
  • 该物业是附属物业。
  • You are binding to a static property.
  • 您绑定到静态属性。

For use as storyboard target, the property specified as propertyName must be a DependencyProperty.

要用作storyboard目标,指定为propertyName的属性必须是DependencyProperty。

#3


3  

(Validation.Errors) references the attached property Errors in the Validation class. Since the binding has a RelativeSource = Self, it's gonna look for the value of that attached property with respect to the TextBox itself.

(Validation.Errors)引用Validation类中的附加属性Errors。由于绑定具有RelativeSource = Self,因此它将查找与TextBox本身相关的附加属性的值。

#4


0  

This below msdn link is neatly explaining about the validation rule and sequences as well as how to use.

下面的msdn链接整齐地解释了验证规则和序列以及如何使用。

http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.errors.aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.errors.aspx

#1


11  

The () parentheses refer to Attached Properties.

()括号引用附加属性。

Binding to an Attached Property

绑定附属物

#2


4  

Quoting the MSDN library (I'm quoting MSDN here because I couldn't have written it down better):

引用MSDN库(我在这里引用MSDN,因为我无法将其写得更好):

This syntax is generally used for one of the following cases:

此语法通常用于以下情况之一:

  • The path is specified in XAML that is in a style or template that does not have a specified TargetType. A qualified usage is generally not valid for cases other than this, because in non-style, non-template cases, the property exists on an instance, not a type.
  • 路径在XAML中指定,该路径位于没有指定TargetType的样式或模板中。合格用法通常对除此之外的其他情况无效,因为在非样式的非模板情况下,该属性存在于实例上,而不是类型。
  • The property is an attached property.
  • 该物业是附属物业。
  • You are binding to a static property.
  • 您绑定到静态属性。

For use as storyboard target, the property specified as propertyName must be a DependencyProperty.

要用作storyboard目标,指定为propertyName的属性必须是DependencyProperty。

#3


3  

(Validation.Errors) references the attached property Errors in the Validation class. Since the binding has a RelativeSource = Self, it's gonna look for the value of that attached property with respect to the TextBox itself.

(Validation.Errors)引用Validation类中的附加属性Errors。由于绑定具有RelativeSource = Self,因此它将查找与TextBox本身相关的附加属性的值。

#4


0  

This below msdn link is neatly explaining about the validation rule and sequences as well as how to use.

下面的msdn链接整齐地解释了验证规则和序列以及如何使用。

http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.errors.aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.validation.errors.aspx