Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
XamNumericEditor for an int field
posted

Hello!

I want to use a NumericEditor for an int Property. In our application, to represent a null int, we use the min value of an int (int.MinValue). I'm trying to represent this particularity in the editor with a ValueToTextConverter (editing) and a ValueToDisplayTextConverter (not editing). The last code is shown below, I've tried various options (MyInt is our encapsulation of an int to represent nullables and other functions). When the value is displayed (not editing) it works fine, but when I enter in the NumericEditor to edit the value, it shows the int.MinValue (-2147483648).

I would like too, to set a max and min value for the int in order to put a range of [-100, 100] and the width of the editor to the minimum size (30) to view those values, I've tried with various masks, but it doesn't work.

 

Thanks a lot in advance,

 Marc.

-- Code

public class IntValueToTextConverter : 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 (MyInt.IsInt(value) && targetType == typeof(string) && (int)value != MyInt.Null)

return Infragistics.Windows.Utilities.ConvertDataValue(value, targetType, editor.FormatProvider, editor.Format);

else

return System.DBNull.Value;//Infragistics.Windows.Utilities.ConvertDataValue(null, 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)

{

return MyInt.Parse(value);

}

}