This is a migrated thread and some comments may be shown as answers.

Cant bind to Integer property

1 Answer 603 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 16 Oct 2012, 05:26 PM
Hello,
trying to bind a RadNumericUpDown to a integer in a datatemplate:
<DataTemplate DataType="{x:Type datatypes:IntTupleInput}">
<telerik:RadNumericUpDown Value="{Binding Value}"  IsInteger="True" ValueFormat="Numeric" />
</DataTemplate>

My Value proerty is defined this way:

public override object Value
       {
           get
           {
               return GetValue();
           }
           set
           {  
               if (IsLinked)
                   throw new RVExecutorException(this, "Non è possibile impostare il valore di un dato che è collegato ad un altro.");
               else
                   SetValue(value);
                 
               FirePropertyChanged("Value");               
           }
       }

the GetValue returns an Integer while the SetValue try to convert the value into integer.

The problem is that I can't see anything in the NumericUpDown box. When I try to put a value inside, I can see into the debug that it is sending a double value like 1.0 or 2.0 to my property (this is not desired, but by now I can convert and store it as an integer). At the moment that the binding reads my proerty Value, I get an error in the output window saying:

'ObjectSourceConverter' converter failed to convert value '100' (type 'Int32'); fallback value will be used, if available. BindingExpression:Path=Value; DataItem='IntTupleInput' (HashCode=64515557); target element is 'RadNumericUpDown' (Name=''); target property is 'Value' (type 'Nullable`1') NotSupportedException:'System.NotSupportedException: DoubleConverter cannot convert from System.Int32.
   in MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
   in MS.Internal.Data.ObjectSourceConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)

this also happen if I try to bind directy to the Integer property int CurrentValue that stores the value (instead of an "object" Value property)

Could you please clarify this behavior??

Thanks,
Simone

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 19 Oct 2012, 02:34 PM
Hi Simone,

The RadNumericUpDown control doesn't support integer input. It supports double input. To make it to display integer it is formatted to the according way, but internally it manages with double type. This is also the behavior in the Silverlight toolkit's control, which we try to follow for consistency.

Regards,
Konstantina
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
NumericUpDown
Asked by
Simon
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or