Binding.Converter Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
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.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<Binding Converter="converterReference"/>
XAML Values
Property Value
Type: System.Windows.Data.IValueConverterThe IValueConverter object that modifies the data.
| Exception | Condition |
|---|---|
| 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}}"/>