Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do parentheses in binding paths mean?

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"
like image 211
igorGIS Avatar asked Jan 17 '13 15:01

igorGIS


People also ask

What is binding path?

Binding paths address the different properties and lists in a model and define how a node in the hierarchical data tree can be found. A binding path consists of a number of name tokens, which are separated by a separator char. In all models provided by the framework, the separator char is the slash "/".

What does binding mean in WPF?

Data binding is a mechanism in WPF applications that provides a simple and easy way for Windows Runtime apps to display and interact with data. In this mechanism, the management of data is entirely separated from the way data. Data binding allows the flow of data between UI elements and data object on user interface.

What does binding mean XAML?

Data binding is a mechanism in XAML applications that provides a simple and easy way for Windows Runtime Apps using partial classes to display and interact with data. The management of data is entirely separated from the way the data is displayed in this mechanism.

What is DataContext in WPF?

The DataContext property is the default source of your bindings, unless you specifically declare another source, like we did in the previous chapter with the ElementName property. It's defined on the FrameworkElement class, which most UI controls, including the WPF Window, inherits from.


3 Answers

The () parentheses refer to Attached Properties.

Binding to an Attached Property

like image 138
Tilak Avatar answered Oct 12 '22 23:10

Tilak


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.

like image 30
Spontifixus Avatar answered Oct 13 '22 01:10

Spontifixus


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

like image 30
Federico Berasategui Avatar answered Oct 13 '22 01:10

Federico Berasategui