I have a lot of numbers to deal with from my UI. I want some of them to be no decimal places, some to be 2 decimals, and others to be however they are entered (3 or 4 decimal places).
I have a converter named DoubleToStringConverter like this:
[ValueConversion(typeof(double), typeof(string))] public class DoubleToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value == null ? null : ((double)value).ToString("#,0.##########"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { double retValue; if (double.TryParse(value as string, out retValue)) { return retValue; } return DependencyProperty.UnsetValue; } } Is there a way to write just one converter to achieve this? It seems there is no way to have a parameterized converter. The StringFormat in xaml seems to conver string to other type of data. It does not allow to display a substring from xaml.
I can only think of making IntegerToStringConverter, Double2ToStringConverter, Double3ToStringConverter, etc. But I'd like to see whether there is a more efficient way.
parameterto specify your significant digits?targetTypeon the backside to determine what to parse. Not sure where you're having an issue here.