Binding.Converter Property

July 28, 2014

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.

Namespace:  System.Windows.Data
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public IValueConverter Converter { get; set; }
<Binding Converter="converterReference"/>

XAML Values

converterReference

A reference to an existing object that implements IValueConverter and functions as a converter. Typically the object is created in a ResourceDictionary and given a key, then referenced by using the StaticResource markup extension. For instance: <Binding Converter="{StaticResource myConverter}" .../>

Property Value

Type: System.Windows.Data.IValueConverter
The IValueConverter object that modifies the data.

ExceptionCondition
InvalidOperationException

The Binding has already been attached to a target element, and cannot be modified.

Create a converter by implementing the IValueConverter interface and implementing the Convert and ConvertBack methods.

XAML Usage Notes

The use of property element syntax to create an object element that fills a Binding.Converter property element is possible, but uncommon. More common is to create an object element in resources and then reference it by key, using attribute syntax.

To use your converter in a binding, first create an instance of your converter class. The following example shows this as a resource in a XAML file.


<phone:PhoneApplicationPage.Resources>
  <local:DateToStringConverter x:Key="Converter1"/>
</phone:PhoneApplicationPage.Resources>


Then set the Converter property for the binding to that instance.


<TextBlock Grid.Column="0" 
    Text="{Binding Month, Converter={StaticResource Converter1}}"/>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft