Binding class

This topic has not yet been rated - Rate this topic

Defines a binding that connects the properties of binding targets and data sources.

Inheritance

Object
  DependencyObject
    BindingBase
      Binding

Syntax

Public Class Binding  
    Inherits BindingBase

<dependencyobject dependencyproperty="bindingString" />

XAML Values

bindingString

A {Binding} markup extension usage. The {Binding} usage can also include a path, and/or one or more property=value pairs that set properties of Binding through the markup extension's argument parsing behavior. The following properties can be referenced and set through a {Binding} markup extension usage: Converter, ConverterLanguage, ConverterParameter, ElementName, Mode, Path, RelativeSource, Source. For more info on this syntax, including info on the string form of each argument, see Binding markup extension.

Attributes

MarshalingBehaviorAttribute(Agile)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Members

The Binding class has these types of members:

Constructors

The Binding class has these constructors.

ConstructorDescription
Binding Initializes a new instance of the Binding class.

 

Methods

The Binding class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject)
SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject)

 

Properties

The Binding class has these properties.

PropertyAccess typeDescription

Converter

Read/writeGets or sets the converter object that is called by the binding engine to modify the data as it is passed between the source and target, or vice versa.

ConverterLanguage

Read/writeGets or sets a value that names the language to pass to any converter specified by the Converter property.

ConverterParameter

Read/writeGets or sets a parameter that can be used in the Converter logic.

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)

ElementName

Read/writeGets or sets the name of the element to use as the binding source for the Binding.

Mode

Read/writeGets or sets a value that indicates the direction of the data flow in the binding.

Path

Read/writeGets or sets the path to the binding source property.

RelativeSource

Read/writeGets or sets the binding source by specifying its location relative to the position of the binding target.

Source

Read/writeGets or sets the data source for the binding.

 

Remarks

The Binding markup extension enables you to specify a Binding value as a single attribute string, including setting Binding properties such as Path and Source.

A Binding object connects a dependency property of a FrameworkElement directly to a data object so that updates to the data object are automatically propagated to the property that uses data binding. The Binding class defines the properties of a binding. Each binding must have a target element, target property, and data source, although some values are provided by default if you don't specify them.

To bind to a property or a subproperty on a data object, set the Path property of the Binding object. For more info on how to set Path in code or in XAML, see PropertyPath syntax.

You can apply an instance of a Binding class to multiple targets. However, you cannot modify the property values of a Binding object after you attach it to a target element.

Note  Calling the FrameworkElement.SetBinding method and passing in a new Binding object won't necessarily remove an existing binding. Instead, you should use the DependencyObject.ClearValue method.

For more info, see Data binding overview.

For more info on XAML attribute usage for properties that can take a Binding, or that can otherwise be set to a data-bound value, see Binding markup extension.

The property that is the target of a data binding must be a dependency property. For more info, see Dependency properties overview.

Examples

The following code example demonstrates how to create a binding in XAML. For the complete code listing, see the XAML data binding sample.


<StackPanel Margin="5">

  <TextBlock Text="Name:" Style="{StaticResource DescriptionTextStyle}" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <TextBox Text="{Binding Path=Name, Mode=TwoWay}" 
    Width="350" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <TextBlock Text="Organization:" Style="{StaticResource DescriptionTextStyle}" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <!-- You can omit the 'Path=' portion of the binding expression. --> 
  <TextBox Text="{Binding Organization, Mode=TwoWay}" Width="350" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

</StackPanel>

The following example code demonstrates how to create a binding in code.

'Create the source string 
Dim s As String = "Hello"

'Create the binding description 
Dim b As New Binding()
b.Mode = BindingMode.OneTime
b.Source = s

'Attach the binding to the target 
MyText.SetBinding(TextBlock.TextProperty, b)

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Namespace

Windows.UI.Xaml.Data
Windows::UI::Xaml::Data [C++]

Metadata

Windows.winmd

See also

XAML data binding sample
Data binding overview
Dependency properties overview
BindingOperations.SetBinding

 

 

Build date: 12/4/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.