Completed
Last Updated: 31 Jan 2024 09:17 by ADMIN
Release R1 2021 SP1
Travis
Created on: 18 Sep 2019 21:16
Category: NumericInput
Type: Bug Report
3
RadNumericInput decimal

I have a Xamarin.Forms app, but I only am using it for UWP at the moment. The plan is to have Android and iOS later, but I am having issues with the RadNumericInput (Xamarin.Forms) and how the decimal key is handled.

Here is my XAML


<tkInput:RadNumericInput Grid.Row="4" Grid.Column="1" Value="{Binding Price, Mode=TwoWay}" StringFormat="{}{0:C2}" />


Right now, "Price" will default to 0. The UI will initially show $0.00 because of the StringFormat. That is working fine. When I put focus into the control, I only see 0, that is also fine. The issue is when I try to type a decimal. The value disappears and I see an issue in my Output that says -- Binding: can not be converted to type 'System.Int32'

 

Example steps:

  • With the value set to 0.00
  • Focus the control -- you will now see just 0
  • Press the decimal key (aka the period key)
  • Notice the error in the Output window in VS and also the control shows nothing at all
  • If you press the decimal key again, you will see two decimals in the control

**** Also, the Version of the Telerik controls I am using is -- 2019.2.603.360. The drop down below doesn't let me choose that version.

7 comments
ADMIN
Georgi
Posted on: 17 Feb 2021 10:18

Hi,

This item is available in latest internal build - LIB 2021.1.216 (16/2/2021)) and it will be also available in the next official release. You can find the LIB as a prerelease nuget or download the assemblies from your account.

Regards,
Georgi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ADMIN
Yana
Posted on: 30 Jun 2020 08:06

Hi Vardan,

I am afraid this issue is not in our immediate plans for the upcoming release as we have tasks with higher priority at this point. Still, we have it in mind and we'll update this item as soon as there is any progress on it.

Regards,
Yana
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Vardan
Posted on: 29 Jun 2020 14:30
I have the same issue and it seems to happen on a new version on controls as well. Do you guys plan to fix this issue? 
ADMIN
Yana
Posted on: 26 Sep 2019 08:49

Hi Travis,

I am sorry for the delayed reply. 

We looked into the issue and indeed, the decimal separator is not handled correctly inside RadNumericInput on UWP ( the erroneous behavior is not reproduced on Android and iOS). I am afraid I could not offer a workaround as this concerns the internal logic of the control.

I understand this issue makes it impossible to enter decimal values in the NumericInput, so I've raised this item's priority and hopefully we'll manage to resolve it soon.

I am sorry for any inconvenience caused.

Regards,
Yana
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
ADMIN
Lance | Senior Manager Technical Support
Posted on: 20 Sep 2019 23:10

Hello Travis,

Thank you for the demo, I can confirm the behavior where all the NumericInput's entered characters are cleared if the user enters a decimal point. The only time it doesn't get reset if there are only multiple decimal points entered.

I have escalated this to the development team and marked the issue Approved. I am unable to find any workaround at the moment. There might be something that can be done with  the NumericInputEntry itself (inside the ControlTemplate see here), but I will need to defer to the team to follow up with you on that.

Thank you for your patience and understanding.

Unrelated Fix

Regarding the output error, as I suspected that can be resolved with a converter. Since the Price property is of type decimal, the converter should be this:

public class DecimalToDoubleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return System.Convert.ToDouble((decimal)value);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return System.Convert.ToDecimal((double?)value);
    }
}

and the XAML would now be:

<ContentPage ...>
 <ContentPage.Resources>
 <views:DecimalToDoubleConverter x:Key="DecToDblConverter" />
 </ContentPage.Resources>

 <StackLayout>
 <telerikInput:RadNumericInput x:Name="numericInput"
                                      Value="{Binding Price, Mode=TwoWay, Converter={StaticResource DecToDblConverter}}"
                                      StringFormat="{}{0:C2}" />
 </StackLayout>
</ContentPage>

Regards,


Lance | Technical Support Engineer, Principal
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Travis
Posted on: 20 Sep 2019 00:26

I have attached a sample app that produces the same issues as I mentioned in my original post's Example steps.

 

I just generated a Xamarin.Forms app with just UWP and then added in the NumericEntry control. Please unzip and follow my Example steps to see the issue.

ADMIN
Lance | Senior Manager Technical Support
Posted on: 18 Sep 2019 23:41

Hello Travis,

I did not see an attached (or download link for) a reproducible project to follow those steps. Can you please share the data model that contains the Price property? According to the error, it is trying to convert a double? (Value is a nullable double) to an int.

If Price is indeed an int (or any type other than double?), the problem can be averted by using a value converter to bridge the gap between the model's property type and the required type.

For example:

// See https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/converters for more information on writing a converter

public class MyIntToDoubleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Convert.ToDouble((int)value); 
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Convert.ToInt((double?)value);
    }
}

It would be used like this

<ContentPage.Resources>
    <yourNamespace:MyIntToDoubleConverter x:Key="IntToDoubleConverter" />
</ContentPage.Resources>

<tkInput:RadNumericInput Grid.Row="4" Grid.Column="1" Value="{Binding Price, Mode=TwoWay, Converter={StaticResource IntToDoubleConverter}" StringFormat="{}{0:C2}" />

Further Investigation

If it is indeed a double, then please reply with the data model and I will build a test app around it. It would also be useful to know the following platform specifics:

  • What is the Min SDK and Target SDK versions for UWP?
  • What Windows 10 version is the app running on?
  • What version of Xamarin.Forms is the project using?

Version Number

Regarding the version selection, it is the first three numbers that distinguish the release ([year].[releasenumber].[monthday]). You can use the following selection in the future:

Regards,
Lance | Technical Support Engineer, Principal
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items