4 Answers, 1 is accepted
Thank you for contacting us.
You can set the data type of the NumericUpDown control to be integer by using the IsInteger property.
<
telerikInput:RadNumericUpDown
x:Name
=
"numeric"
IsInteger
=
"True"
/>
If you have further questions please feel free to contact us again.
Greetings,
Konstantina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thanks again.
Straight to your question.
With property IsInteger="True" you will get the values of the NumericUpDown as an integer.
If you have further questions please feel free to contact us again.
All the best,
Konstantina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Hello,
I was set the IsInteger property to True with two way binding to a property of type Object. When I add the property to the watch, I can see that the value is Double. I am using the latest Telerik version. Can you help me?
Telerik don't execute any specific code for the conversion. The IsInteger property only format the value to look like an integer. The value in the editor is still double. If you bind the Value property to an integer property, the WPF framework will just do the conversion automatically. The framework is probably something very similar to this:
double myDouble = 5d;
int myInt = (int)myDouble;
This won't work when you data bind the property to a view model property of type Object. In this case the view model will get the property as a plain Double. To achieve your requirement, you can cast the value on the property setter. For example:
public object MyValue
{
get { return myValue; }
set
{
myValue = (int)value;
OnPropertyChanged("MyValue");
}
}
Or just use an integer typed property.
Hey,
If telerik is doing some conversion when IsInteger is set to True, it shall be doing that anyway, without checking the target type. My type is Object because I am using it in many view models. For each view model I have a DataTemplateSelector. In the case I need int type, I put the RadNumericUpDown. My value can also be null because it is a not mandatory field but it is not relevant to the question. I will not add casting to int because it is the same view model for all types and I dont think that I should add specific functionality for UI. Tomorrow if I want to change the RadNumericUpDown with another control, I will not need that logic. Can you add that basic funcionality please?
I wlll appreciate if you open a ticket for that, my company is using Telerik license of course.
Telerik do not do any conversion for the Value of the control. The IsInteger property serves only to format the display text. The value goes as integer to the view model (when the bound property is of type Int32), because the native WPF data binding used to link the Value with the view model property can handle this type of conversions automatically. Even if you don't set the IsInteger property to True, this conversion will happen and you will end up with an integer value in the view model (in case the data bound property is of type int).
Because the bound property on your side is of type Object, the WPF binding will use the original value coming from the Value property of RadNumericUpDown, thus it will store it as Double (boxed in the Object property field).
Changing this behavior and converting the value of the Value property to int when IsInteger is true will cause a breaking change in the behavior of the control.
If you expect nullable data, I would suggest you to use the nullable primitive type, instead of Object. For example: public int? MyInt { get; set; }. Or if you can't make changes in your model, then you can data bind the Value property using an IValueConverter. This will allow you to convert the Double value to an integer in the ConvertBack() method.
About the support ticket, you can open one using the account to which the Telerik license is assigned.