Binding Binding Binding Binding Class

Definition

Provides high-level access to the definition of a binding, which connects the properties of binding target objects (typically, WPF elements), and any data source (for example, a database, an XML file, or any object that contains data).

public ref class Binding : System::Windows::Data::BindingBase
public class Binding : System.Windows.Data.BindingBase
type Binding = class
    inherit BindingBase
Public Class Binding
Inherits BindingBase
Inheritance

Remarks

Windows Presentation Foundation (WPF) data binding provides a simple and consistent way for applications to present and interact with data. Data binding enables you to synchronize the values of the properties of two different objects.

To establish a binding, use the Binding class or one of the other classes that inherit BindingBase. Regardless of what object you are binding and the nature of your data source, each binding follows the model illustrated by the following figure.

Basic data binding diagram

The figure demonstrates the following fundamental WPF data binding concepts.

  • 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 example, if you want to bind the content of a TextBox to the Name property of an Employee object, your target object is the TextBox, the target property is the Text property, the value to use is Name, and the source object is the Employee object.

  • The target property must be a dependency property. This also means that you cannot bind a field. Most properties of UIElement objects are dependency properties and most dependency properties, except read-only ones, support data binding by default. (Only DependencyObject types can define dependency properties and all UIElement objects derive from DependencyObject.)

  • Although not specified in the figure, it should be noted that the binding source object is not restricted to being a custom CLR object. WPF data binding supports data in the form of CLR objects and XML. To provide some examples, your binding source may be a UIElement, any list object, a CLR object that is associated with ADO.NET data or Web Services, or an XmlNode that contains your XML data.

Use the Mode property to specify the direction of the data flow. To detect source changes in one-way or two-way bindings, the source must implement a suitable property change notification mechanism such as INotifyPropertyChanged. For an example, see How to: Implement Property Change Notification. The UpdateSourceTrigger property specifies the timing of source updates. For more information, see "Basic Data Binding Concepts" in Data Binding Overview.

XAML Attribute Usage

<object property="{Binding  declaration}"/>  

XAML Values

declaration
Zero or more attribute-assignment clauses separated by commas (,). For more information, see Binding Markup Extension or Binding Declarations Overview.

Constructors

Binding() Binding() Binding() Binding()

Initializes a new instance of the Binding class.

Binding(String) Binding(String) Binding(String) Binding(String)

Initializes a new instance of the Binding class with an initial path.

Fields

DoNothing DoNothing DoNothing DoNothing

Used as a returned value to instruct the binding engine not to perform any action.

IndexerName IndexerName IndexerName IndexerName

Used as the PropertyName of PropertyChangedEventArgs to indicate that an indexer property has changed.

SourceUpdatedEvent SourceUpdatedEvent SourceUpdatedEvent SourceUpdatedEvent

Identifies the SourceUpdated attached event.

TargetUpdatedEvent TargetUpdatedEvent TargetUpdatedEvent TargetUpdatedEvent

Identifies the TargetUpdated attached event.

XmlNamespaceManagerProperty XmlNamespaceManagerProperty XmlNamespaceManagerProperty XmlNamespaceManagerProperty

Identifies the XmlNamespaceManager attached property.

Properties

AsyncState AsyncState AsyncState AsyncState

Gets or sets opaque data passed to the asynchronous data dispatcher.

BindingGroupName BindingGroupName BindingGroupName BindingGroupName

Gets or sets the name of the BindingGroup to which this binding belongs.

(Inherited from BindingBase)
BindsDirectlyToSource BindsDirectlyToSource BindsDirectlyToSource BindsDirectlyToSource

Gets or sets a value that indicates whether to evaluate the Path relative to the data item or the DataSourceProvider object.

Converter Converter Converter Converter

Gets or sets the converter to use.

ConverterCulture ConverterCulture ConverterCulture ConverterCulture

Gets or sets the culture in which to evaluate the converter.

ConverterParameter ConverterParameter ConverterParameter ConverterParameter

Gets or sets the parameter to pass to the Converter.

Delay Delay Delay Delay

Gets or sets the amount of time, in milliseconds, to wait before updating the binding source after the value on the target changes.

(Inherited from BindingBase)
ElementName ElementName ElementName ElementName

Gets or sets the name of the element to use as the binding source object.

FallbackValue FallbackValue FallbackValue FallbackValue

Gets or sets the value to use when the binding is unable to return a value.

(Inherited from BindingBase)
IsAsync IsAsync IsAsync IsAsync

Gets or sets a value that indicates whether the Binding should get and set values asynchronously.

Mode Mode Mode Mode

Gets or sets a value that indicates the direction of the data flow in the binding.

NotifyOnSourceUpdated NotifyOnSourceUpdated NotifyOnSourceUpdated NotifyOnSourceUpdated

Gets or sets a value that indicates whether to raise the SourceUpdated event when a value is transferred from the binding target to the binding source.

NotifyOnTargetUpdated NotifyOnTargetUpdated NotifyOnTargetUpdated NotifyOnTargetUpdated

Gets or sets a value that indicates whether to raise the TargetUpdated event when a value is transferred from the binding source to the binding target.

NotifyOnValidationError NotifyOnValidationError NotifyOnValidationError NotifyOnValidationError

Gets or sets a value that indicates whether to raise the Error attached event on the bound object.

Path Path Path Path

Gets or sets the path to the binding source property.

RelativeSource RelativeSource RelativeSource RelativeSource

Gets or sets the binding source by specifying its location relative to the position of the binding target.

Source Source Source Source

Gets or sets the object to use as the binding source.

StringFormat StringFormat StringFormat StringFormat

Gets or sets a string that specifies how to format the binding if it displays the bound value as a string.

(Inherited from BindingBase)
TargetNullValue TargetNullValue TargetNullValue TargetNullValue

Gets or sets the value that is used in the target when the value of the source is null.

(Inherited from BindingBase)
UpdateSourceExceptionFilter UpdateSourceExceptionFilter UpdateSourceExceptionFilter UpdateSourceExceptionFilter

Gets or sets a handler you can use to provide custom logic for handling exceptions that the binding engine encounters during the update of the binding source value. This is only applicable if you have associated an ExceptionValidationRule with your binding.

UpdateSourceTrigger UpdateSourceTrigger UpdateSourceTrigger UpdateSourceTrigger

Gets or sets a value that determines the timing of binding source updates.

ValidatesOnDataErrors ValidatesOnDataErrors ValidatesOnDataErrors ValidatesOnDataErrors

Gets or sets a value that indicates whether to include the DataErrorValidationRule.

ValidatesOnExceptions ValidatesOnExceptions ValidatesOnExceptions ValidatesOnExceptions

Gets or sets a value that indicates whether to include the ExceptionValidationRule.

ValidatesOnNotifyDataErrors ValidatesOnNotifyDataErrors ValidatesOnNotifyDataErrors ValidatesOnNotifyDataErrors

Gets or sets a value that indicates whether to include the NotifyDataErrorValidationRule.

ValidationRules ValidationRules ValidationRules ValidationRules

Gets a collection of rules that check the validity of the user input.

XPath XPath XPath XPath

Gets or sets an XPath query that returns the value on the XML binding source to use.

Attached Properties

XmlNamespaceManager XmlNamespaceManager XmlNamespaceManager XmlNamespaceManager

Methods

AddSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>)

Adds a handler for the SourceUpdated attached event.

AddTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) AddTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>)

Adds a handler for the TargetUpdated attached event.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetXmlNamespaceManager(DependencyObject) GetXmlNamespaceManager(DependencyObject) GetXmlNamespaceManager(DependencyObject) GetXmlNamespaceManager(DependencyObject)

Returns an XML namespace manager object used by the binding attached to the specified object.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ProvideValue(IServiceProvider) ProvideValue(IServiceProvider) ProvideValue(IServiceProvider) ProvideValue(IServiceProvider)

Returns an object that should be set on the property where this binding and extension are applied.

(Inherited from BindingBase)
RemoveSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveSourceUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>)

Removes a handler for the SourceUpdated attached event.

RemoveTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>) RemoveTargetUpdatedHandler(DependencyObject, EventHandler<DataTransferEventArgs>)

Removes a handler for the TargetUpdated attached event.

SetXmlNamespaceManager(DependencyObject, XmlNamespaceManager) SetXmlNamespaceManager(DependencyObject, XmlNamespaceManager) SetXmlNamespaceManager(DependencyObject, XmlNamespaceManager) SetXmlNamespaceManager(DependencyObject, XmlNamespaceManager)

Sets a namespace manager object used by the binding attached to the provided element.

ShouldSerializeFallbackValue() ShouldSerializeFallbackValue() ShouldSerializeFallbackValue() ShouldSerializeFallbackValue()

Returns a value that indicates whether serialization processes should serialize the effective value of the FallbackValue property on instances of this class.

(Inherited from BindingBase)
ShouldSerializePath() ShouldSerializePath() ShouldSerializePath() ShouldSerializePath()

Indicates whether the Path property should be persisted.

ShouldSerializeSource() ShouldSerializeSource() ShouldSerializeSource() ShouldSerializeSource()

Indicates whether the Source property should be persisted.

ShouldSerializeTargetNullValue() ShouldSerializeTargetNullValue() ShouldSerializeTargetNullValue() ShouldSerializeTargetNullValue()

Returns a value that indicates whether the TargetNullValue property should be serialized.

(Inherited from BindingBase)
ShouldSerializeValidationRules() ShouldSerializeValidationRules() ShouldSerializeValidationRules() ShouldSerializeValidationRules()

Indicates whether the ValidationRules property should be persisted.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Attached Events

SourceUpdated SourceUpdated SourceUpdated SourceUpdated
TargetUpdated TargetUpdated TargetUpdated TargetUpdated

Applies to

See Also