DoubleEditBox and StringValueConverter

Editors for WPF Forum

Posted 8 years ago by George
Version: 11.1.0545
Avatar
I am trying to append units and get custom formatting to work with my DoubleEditBox. To do that, I have tried to implement an IStringValueConverter<double?> to set to the DoubleEditBox so that I can do custom formatting in it.

However, none of my methods are called in my StringValueConverter if I put in the necessary breakpoints.

public class DSVConverter : IStringValueConverter<double?>
{
public DSVConverter()
{

}

#region IStringValueConverter<double> Members

public bool CanConvertFromString(string text)
{
return true;
}

public bool CanConvertToString(double value)
{
return true;
}

public double ConvertFromString(string text)
{
return double.Parse(text);
}

public string ConvertToString(double value)
{
return value.ToString("##.00");
}

#endregion
}

<editors:DoubleEditBox Value="{Binding Height}"
StringValueConverter="{StaticResource dsvConverter}"/>

Could you please help me identify what I am doing wrong? Could you give me a sample on how to make this work?

Thanks in advance

[Modified at 09/08/2011 09:08 AM]

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi George,

The StringValueConverter is only used to the convert the DoubleEditBox's value to and from a string, such as for clipboard operations. It doesn't have any affect on the display.

If you just want to include a fixed unit in the DoubleEditBox, you can take a look at our DoubleEditBox Temperature Entry QuickStart. If you want to include a unit that can be changed by the user, you'd need to include a ComboBox (or similar control) in the DoubleEditBox (much like shown in the QuickStart).


Actipro Software Support

Posted 8 years ago by George
Avatar
Is there any way by which I can get hold of the ValueConverter that is used by the DoubleEditBox so that I can set it to something that can do custom formatting for me?

For instance, I would want to use "#.00 kW" as my Format string to format my values but unfortunately, that does not work if I put in in Format. Neither does "#.00" work.
It throws an exception.
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi George,

Sorry, but the DoubleEditBox does not currently support the Double's custom format strings. It only supports the standard format strings. So you could use "F2" as the format string to get the 2 decimal places, then include the units as shown in the DoubleEditBox Temperature Entry QuickStart.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 12 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.