12

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

<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"
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
igorGIS
  • 1,888
  • 4
  • 27
  • 41

4 Answers4

16

The () parentheses refer to Attached Properties.

Binding to an Attached Property

Tilak
  • 30,108
  • 19
  • 83
  • 131
7

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

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.
  • 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.

Community
  • 1
  • 1
Spontifixus
  • 6,570
  • 9
  • 45
  • 63
5

(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.

Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
0

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

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

Smaug
  • 2,625
  • 5
  • 28
  • 44