Version

FormatProvider Property

Specifies format provider used for converting between value and text.
Syntax
'Declaration
 
Public Property FormatProvider As IFormatProvider
public IFormatProvider FormatProvider {get; set;}
Remarks

FormatProvider is used to convert between text and the value. The editor will use this along with Format property setting to convert the value to text for display purposes. Note that when editing, only the FormatProvider will be used and the Format property will be ignored. This is to facilitate easier editing of values without the clutter of formatting symbols.

The default behavior can be changed by providing custom conversion logic using ValueToTextConverter and ValueToDisplayTextConverter properties.

Note: FormatProvider property is of type IFormatProvider interface. IFormatProvider is implemented by CultureInfo object therefore this property can be set to an instance of CultureInfo. You can also use DateTimeFormatInfo or NumberFormatInfo as these implement the interface as well.

Example
The following code sets Format of a XamTextEditor to "C" and FormatProvider to a CultureInfo instance. Note that the ValueType is set to Decimal. Formats are specific to type. So make sure the format that you set matches the value type of the editor. The text editor will display the value 10 formatted with currency format of the set format provider. Also any new values entered in the editor will be automatically formatted upon leaving the editor control.

<!--This code defines a XamTextEditor. C#/VB code snippets set the Format and FormatProvider properties-->
<igEditors:XamTextEditor x:Name="textEditor1"  />
Protected Overrides Sub OnInitialized(ByVal e As EventArgs)

    MyBase.OnInitialized(e)

    Me.textEditor1.ValueType = GetType(Decimal)
    Me.textEditor1.Format = "C"
    Me.textEditor1.FormatProvider = New System.Globalization.CultureInfo("fr-FR")
    Me.textEditor1.Value = 10
    Debug.WriteLine("Text = " & Me.textEditor1.DisplayText)
End Sub
protected override void OnInitialized( EventArgs e )
{
	base.OnInitialized( e );

	this.textEditor1.ValueType = typeof( Decimal );
	this.textEditor1.Format = "C";
	this.textEditor1.FormatProvider = new System.Globalization.CultureInfo( "fr-FR" );
	this.textEditor1.Value = 10;
	Debug.WriteLine( "Text = " + this.textEditor1.DisplayText );
}
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