3 out of 6 rated this helpful - Rate this topic

Binding Class

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

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public class Binding : BindingBase
<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.

The Binding type exposes the following members.

  Name Description
Public method Binding() Initializes a new instance of the Binding class.
Public method Binding(String) Initializes a new instance of the Binding class with an initial path.
Top
  Name Description
Public property AsyncState Infrastructure. Gets or sets opaque data passed to the asynchronous data dispatcher.
Public property BindingGroupName Gets or sets the name of the BindingGroup to which this binding belongs. (Inherited from BindingBase.)
Public property BindsDirectlyToSource Gets or sets a value that indicates whether to evaluate the Path relative to the data item or the DataSourceProvider object.
Public property Converter Gets or sets the converter to use.
Public property ConverterCulture Gets or sets the culture in which to evaluate the converter.
Public property ConverterParameter Gets or sets the parameter to pass to the Converter.
Public property ElementName Gets or sets the name of the element to use as the binding source object.
Public property FallbackValue Gets or sets the value to use when the binding is unable to return a value. (Inherited from BindingBase.)
Public property IsAsync Gets or sets a value that indicates whether the Binding should get and set values asynchronously.
Public property Mode Gets or sets a value that indicates the direction of the data flow in the binding.
Public property 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.
Public property 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.
Public property NotifyOnValidationError Gets or sets a value that indicates whether to raise the Error attached event on the bound object.
Public property Path Gets or sets the path to the binding source property.
Public property RelativeSource Gets or sets the binding source by specifying its location relative to the position of the binding target.
Public property Source Gets or sets the object to use as the binding source.
Public property 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.)
Public property TargetNullValue Gets or sets the value that is used in the target when the value of the source is null. (Inherited from BindingBase.)
Public property 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.
Public property UpdateSourceTrigger Gets or sets a value that determines the timing of binding source updates.
Public property ValidatesOnDataErrors Gets or sets a value that indicates whether to include the DataErrorValidationRule.
Public property ValidatesOnExceptions Gets or sets a value that indicates whether to include the ExceptionValidationRule.
Public property ValidationRules Gets a collection of rules that check the validity of the user input.
Public property XPath Gets or sets an XPath query that returns the value on the XML binding source to use.
Top
  Name Description
Public attached property XmlNamespaceManager Gets or sets the XmlNamespaceManager used to perform namespace-aware XPath queries in XML bindings.
Top
  Name Description
Public method Static member AddSourceUpdatedHandler Adds a handler for the SourceUpdated attached event.
Public method Static member AddTargetUpdatedHandler Adds a handler for the TargetUpdated attached event.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Static member GetXmlNamespaceManager Returns an XML namespace manager object used by the binding attached to the specified object.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ProvideValue Returns an object that should be set on the property where this binding and extension are applied. (Inherited from BindingBase.)
Public method Static member RemoveSourceUpdatedHandler Removes a handler for the SourceUpdated attached event.
Public method Static member RemoveTargetUpdatedHandler Removes a handler for the TargetUpdated attached event.
Public method Static member SetXmlNamespaceManager Sets a namespace manager object used by the binding attached to the provided element.
Public method 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.)
Public method ShouldSerializePath Indicates whether the Path property should be persisted.
Public method ShouldSerializeSource Indicates whether the Source property should be persisted.
Public method ShouldSerializeTargetNullValue Returns a value that indicates whether the TargetNullValue property should be serialized. (Inherited from BindingBase.)
Public method ShouldSerializeValidationRules Indicates whether the ValidationRules property should be persisted.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public attached event SourceUpdated Occurs when a value is transferred from the binding target to the binding source, but only for bindings with the NotifyOnSourceUpdated value set to true.
Public attached event TargetUpdated Occurs when a value is transferred from the binding source to the binding target, but only for bindings with the NotifyOnTargetUpdated value set to true.
Top
  Name Description
Public field Static member DoNothing Used as a returned value to instruct the binding engine not to perform any action.
Public field Static member IndexerName Used as the PropertyName of System.ComponentModel.PropertyChangedEventArgs to indicate that an indexer property has changed.
Public field Static member SourceUpdatedEvent Identifies the SourceUpdated attached event.
Public field Static member TargetUpdatedEvent Identifies the TargetUpdated attached event.
Public field Static member XmlNamespaceManagerProperty Identifies the XmlNamespaceManager attached property.
Top

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.

This example shows you how to create a simple Binding.

In this example, you have a Person object with a string property named PersonName. The Person object is defined in the namespace called SDKSample.

The following example instantiates the Person object with a PersonName property value of Joe. This is done in the Resources section and assigned an x:Key.


<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:src="clr-namespace:SDKSample"
  SizeToContent="WidthAndHeight"
  Title="Simple Data Binding Sample">

  <Window.Resources>
    <src:Person x:Key="myDataSource" PersonName="Joe"/>


...


</Window.Resources>


...


</Window>


To bind to the PersonName property you would do the following:


<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=PersonName}"/>


As a result, the TextBlock appears with the value "Joe".

More Code

How to: Specify the Binding Source In data binding, the binding source object refers to the object you obtain your data from. This topic describes the different ways of specifying the binding source.
How to: Create a Binding in Code This example shows how to create and set a Binding in code.
How to: Bind to XML Data Using an XMLDataProvider and XPath Queries This example shows how to bind to XML data using an XmlDataProvider.
How to: Implement Property Change Notification To support OneWay or TwoWay binding to enable your binding target properties to automatically reflect the dynamic changes of the binding source (for example, to have the preview pane updated automatically when the user edits a form), your class needs to provide the proper property changed notifications. This example shows how to create a class that implements INotifyPropertyChanged.
How to: Specify the Direction of the Binding This example shows how to specify whether the binding updates only the binding target (target) property, the binding source (source) property, or both the target property and the source property.
How to: Control When the TextBox Text Updates the Source This topic describes how to use the UpdateSourceTrigger property to control the timing of binding source updates. The topic uses the TextBox control as an example.
How to: Bind to an ADO.NET Data Source This example shows how to bind a Windows Presentation Foundation (WPF) ListBox control to an ADO.NET DataSet.
How to: Sort Data in a View This example describes how to sort data in a view.
How to: Filter Data in a View This example shows how to filter data in a view.
How to: Bind to an Enumeration This example shows how to bind to an enumeration by binding to the enumeration's GetValues method.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Committing Edit
I'm having issues commiting my edit to the datatable.  In windows forms, we were able to get away with using mybindingsource.endedit();.  Anything similar in WPF?  How do I force my textbox to write to my datatable in WPF?
Binding should be Cloneable