Click or drag to resize
Binding Class
Defines a binding that connects the properties of binding targets and data sources.
Inheritance Hierarchy

Namespace: Windows.UI.Xaml.Data
Assembly: CSharpXamlForHtml5 (in CSharpXamlForHtml5.dll) Version: 1.0.0.0
Syntax
C#
[ContentPropertyAttribute("Path")]
public class Binding : BindingBase

The Binding type exposes the following members.

Constructors
  NameDescription
Public methodBinding
Initializes a new instance of the Binding class.
Public methodBinding(String)
Initializes a new instance of the Binding class with the given path.
Top
Methods
  NameDescription
Public methodEquals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProvideValue
When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.
(Inherited from MarkupExtension.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyConverter
Gets 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. Returns the IValueConverter object that modifies the data.
Public propertyConverterLanguage
Gets or sets a value that names the language to pass to any converter specified by the Converter property. Returns a string that names a language. Interpretation of this value is ultimately up to the converter logic.
Public propertyConverterParameter
Gets or sets a parameter that can be used in the Converter logic. Returns a parameter to be passed to the Converter. This can be used in the conversion logic. The default is null.
Public propertyElementName
Gets or sets the name of the element to use as the binding source for the Binding. Returns the value of the Name property or x:Name attribute for the element to bind to. The default is null.
Public propertyMode
Gets or sets a value that indicates the direction of the data flow in the binding. Returns one of the BindingMode values.
Public propertyPath
Gets or sets the path to the binding source property. Returns the property path for the source of the binding.
Public propertyRelativeSource
Gets or sets the binding source by specifying its location relative to the position of the binding target. Returns the relative location of the binding source to use. The default is null.
Public propertySource
Gets or sets the data source for the binding. Returns the source object that contains the data for the binding.
Top
Examples
You can add a Binding using XAML as follows:
C#
MyTextBlock.DataContext = myPlanet;
XAML
<TextBlock x:Name="MyTextBlock" Text="{Binding Size}" HorizontalAlignment="Left" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
Note: you can create the Binding directly using C#:
C#
Binding myBinding = new Binding("Size");
MyTextBlock.SetBinding(TextBlock.TextProperty, myBinding);
MyTextBlock.DataContext = myPlanet;
Here is another example using the TwoWay mode, and also using a Converter:
C#
MyTextBox.DataContext = myPlanet;
XAML
<Border>
<!-- We define the Converter: -->
    <Border.Resources>
        <local:KilometersToMilesConverter x:Key="KilometersToMilesConverter" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyAssembly.MyApp" />
    </Border.Resources>
    <TextBox x:Name="MyTextBox" Text="{Binding Length, Mode=TwoWay, Converter={StaticResource KilometersToMilesConverter}}" HorizontalAlignment="Left" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
</Border>
Using C#:
C#
Binding myBinding = new Binding("Size");

//we set the binding in TwoWay mode:
myBinding.Mode = BindingMode.TwoWay;

//We create the converter:
myBinding.Converter = new KilometersToMilesConverter();

MyTextBox.SetBinding(TextBox.TextProperty, myBinding);
MyTextBox.DataContext = myPlanet;
See Also