Version

ValueToDisplayTextConverter Property

Specifies the converter used for converting between display text and value.
Syntax
'Declaration
 
Public Property ValueToDisplayTextConverter As IValueConverter
public IValueConverter ValueToDisplayTextConverter {get; set;}
Remarks

The conversions between the 'string' and the ValueType by default are done using built in conversion logic. You can override the default conversion logic by setting the ValueToDisplayTextConverter and ValueEditor.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 System.ValueType property.

For most situations the default conversion logic along with the ValueEditor.FormatProvider and ValueEditor.Format format properties should be sufficient in providing various formatting capabilities.

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 value into display text. Examples where this would be needed are if you want to present a value like tomorrow and yesterday's dates as date as words 'Tomorrow' and 'Yesterday' respectively, or apply any kind of custom formatting that could not be specified using ValueEditor.FormatProvider and ValueEditor.Format property settings.

Example
The following code demonstrates how to create custom value to text converter. In C# and VB code it implements IValueConverter on MyPointConverter and assigns instances of MyPointConverter to ValueToTextConverter and ValueToDisplayTextConverter properties of ValueEditor in XAML code. With the following code, the XamTextEditor will accept Point objects via it's Value property and it will also be able to parse user input in the form of two integer values separated by comma (',') into Point object which will be returned by the Value property. Note: Make sure to define correct namespaces in the XAML to be able to refer to classes correctly in XAML.

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 );
	}
}
<igEditors:XamTextEditor x:Name="pointEditor" 
                                             
ValueType="{x:Type Point}"
                                             
>

    
<!--ValueToTextConverter gets used when in edit mode to convert value to
    text and text (user input) into value.
-->
    
<igEditors:XamTextEditor.ValueToTextConverter>
        
<local:MyPointConverter />
    
</igEditors:XamTextEditor.ValueToTextConverter>

    
<!--You can specify a different converter for display mode which gets
    used when not in edit mode. This converter only gets used for converting
    value to text.
-->
    
<igEditors:XamTextEditor.ValueToDisplayTextConverter>
        
<local:MyPointConverter />
    
</igEditors:XamTextEditor.ValueToDisplayTextConverter>
            
</igEditors:XamTextEditor>
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
Requirements

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

See Also