Binding.Path Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the path to the binding source property.
public:
property System::Windows::PropertyPath ^ Path { System::Windows::PropertyPath ^ get(); void set(System::Windows::PropertyPath ^ value); };
public System.Windows.PropertyPath Path { get; set; }
member this.Path : System.Windows.PropertyPath with get, set
Public Property Path As PropertyPath
Property Value
The path to the binding source. The default is null
.
Examples
The following example shows a style trigger that creates a ToolTip that reports a validation error message. The value of the setter binds to the error content of the current TextBox (the TextBox using the style) using the RelativeSource property. For more information on this example, see How to: Implement Binding Validation.
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)/ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
Remarks
Each binding typically has these four components: a binding target object, a target property, a binding source, and a path to the value in the binding source to use. For more information about these data binding concepts, see Data Binding Overview.
Use the Path property to specify the source value you want to bind to:
In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as
Path=PropertyName
.Subproperties of a property can be specified by a syntax similar to that used in C#. For instance, the clause
Path=ShoppingCart.Order
sets the binding to the subpropertyOrder
of the object or propertyShoppingCart
.To bind to an attached property, place parentheses around the attached property. For example, to bind to the attached property DockPanel.Dock, the syntax is
Path=(DockPanel.Dock)
.Indexers of a property can be specified within square brackets following the property name where the indexer is applied. For instance, the clause
Path=ShoppingCart[0]
sets the binding to the index that corresponds to how your property's internal indexing handles the literal string "0". Multiple indexers are also supported.Indexers and subproperties can be mixed in a
Path
clause; for example,Path=ShoppingCart.ShippingInfo[MailingAddress,Street].
Inside indexers you can have multiple indexer parameters separated by commas (,). The type of each parameter can be specified with parentheses. For example, you can have
Path="[(sys:Int32)42,(sys:Int32)24]"
, wheresys
is mapped to theSystem
namespace.When the source is a collection view, the current item can be specified with a slash (/). For example, the clause
Path=/
sets the binding to the current item in the view. When the source is a collection, this syntax specifies the current item of the default collection view.Property names and slashes can be combined to traverse properties that are collections. For example,
Path=/Offices/ManagerName
specifies the current item of the source collection, which contains anOffices
property that is also a collection. Its current item is an object that contains aManagerName
property.Optionally, a period (.) path can be used to bind to the current source. For example,
Text="{Binding}"
is equivalent toText="{Binding Path=.}"
.
For information about path syntax, see Binding Declarations Overview or PropertyPath XAML Syntax.
For XML bindings, see the XPath property.
To bind to an entire object, you do not need to specify the Path property. For more information, see "Specifying the Path to the Value" in Data Binding Overview.