'Declaration Public Property ValueToTextConverter As IValueConverter
public IValueConverter ValueToTextConverter {get; set;}
The conversions between the 'string' and the ValueType by default are done using built in conversion logic. You can override the conversion logic by setting the ValueToDisplayTextConverter and ValueToTextConverter. ValueToTextConverter is used when the editor is in edit mode where as ValueToDisplayTextConverter is used when the editor is not in edit mode.
Note: An editor can edit values of types other than 'string'. For example, a XamTextEditor can edit values of types DateTime. You can specify the type of values being edited by the editor using the ValueType property.
Although the built-in default conversion logic should be sufficient for most situations, you may want make use of this functionality to provide custom logic for converting user input into value type object. Examples where this would be needed are if you are editing custom objects where the built-in conversion logic would not know how to convert text into custom object type. Or you want to support entering certain symbols in the text that signify certain aspect of the value - for example you want 'k' in '2k' to be interpreted as 1000 magnitude, or +1d to be interpreted as tomorrow's date when editing DateTime.
Note that not all derived editors support or utilize ValueToTextConverter. Editors where value to text conversions are performed intrinsically, such as XamComboEditor where both the value and text are retrieved from the selected item, do not support ValueToTextConverter.
public class MyPointConverter : IValueConverter { // Convert gets called to convert value to text. public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { ValueEditor editor = parameter as ValueEditor; if ( value is Point && targetType == typeof( string ) ) value.ToString( ); return Infragistics.Windows.Utilities.ConvertDataValue( value, targetType, editor.FormatProvider, editor.Format ); } // ConvertBack gets called to convert user input into to value. public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { string text = null != value ? value.ToString( ) : string.Empty; return Point.Parse( text ); } }
Public Class MyPointConverter Implements IValueConverter ' Convert gets called to convert value to text. Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert Dim editor As ValueEditor = DirectCast(parameter, ValueEditor) If TypeOf value Is Point AndAlso targetType Is GetType(String) Then value.ToString() End If Return Infragistics.Windows.Utilities.ConvertDataValue(value, targetType, editor.FormatProvider, editor.Format) End Function ' ConvertBack gets called to convert user input into to value. Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Dim text As String = String.Empty If Not Nothing Is value Then text = value.ToString() End If Return Point.Parse(text) End Function End Class
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, 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