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

DateEditor throws exception on Android

6 Answers 79 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Edwin
Top achievements
Rank 1
Edwin asked on 31 Dec 2016, 05:41 AM
The DateEditor is throwing an exception on Android trying to cast a java Calendar object to a DateTime object. I thought this would get handled automatically by the DataForm package? Is there some step I missed? I have reverted my code to use the Xamarin DatePicker in the meantime but wanted to see if can get a resolution for this as I would really like to take advantage of what the DataForm has to offer. I'm using version 2016.3.1202.5.

6 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 04 Jan 2017, 10:18 AM
Hello Edwin,

Thank you for contacting us. Could you please tell us more about your scenario? A code snippet, a sample project or anything that could help us reproduce the issue would be appreciated. I look forward to your reply.

Regards,
Rosy Topchiyska
Telerik by Progress
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
0
Edwin
Top achievements
Rank 1
answered on 04 Jan 2017, 06:30 PM

Here's the xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:AcoadApp.ViewModels;assembly=AcoadApp"
             xmlns:telerikInput="clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input"
             x:Class="AcoadApp.Views.AddMatchPage"
             Title="New Match">
  <telerikInput:RadDataForm x:Name="dataForm">
    <telerikInput:RadDataForm.Source>
        <local:DataSource />
    </telerikInput:RadDataForm.Source>
</telerikInput:RadDataForm>
</ContentPage>

 

Here's the code behind

public partial class AddMatchPage : ContentPage
{
        public AddMatchPage()
        {
            InitializeComponent();
            dataForm.RegisterEditor(nameof(DataSource.Date), Telerik.XamarinForms.Input.EditorType.DateEditor);
        }

        protected override async void OnAppearing()
        {
            base.OnAppearing();
        }
}

 

And the DataSource file

 

public class DataSource : INotifyPropertyChanged
{
        DateTime _date = DateTime.Now;

        [DisplayOptions(Header = "Name")]
        public DateTime Date
        {
            get { return _date; }
            set { _date = value; OnPropertyChanged(); }
        }

        public DataSource() { }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
}

 

When going to the page I get the following exception - 

 

Java.Lang.Error: DataFormTextEditor does not support properties of type Calendar. Please specify a value converter for your property.

 

I guess I need to create a converter for this? I assumed that the control would handle the conversion itself. I looked at the ConverterAttribute example in the docs but don't know how to create one to handle this situation or if I even need to do that.

 

0
Edwin
Top achievements
Rank 1
answered on 04 Jan 2017, 06:36 PM
Sorry I forgot to add that I'm using the latest version of xamarin forms and testing this on an Android emulator running Android KitKat (4.4).
0
Rosy Topchiyska
Telerik team
answered on 09 Jan 2017, 05:23 PM
Hi Edwin,

Thank you for the information. This exception is thrown only when you do not explicitly register a DateEditor for a property of type DateTime, which is not your case. I could not reproduce this issue on our side. Could you please take a look at the attached project and let us know if you get this issue with it?

Regards,
Rosy Topchiyska
Telerik by Progress
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
0
Edwin
Top achievements
Rank 1
answered on 09 Jan 2017, 05:33 PM
Thank you for taking a look. I will try the sample project you provided and let you know.
0
Edwin
Top achievements
Rank 1
answered on 10 Feb 2017, 10:52 PM

It took me awhile to get around to this but I finally tested the sample project and it works fine so it must be something specific to my project or the version of Telerik I'm using. I'll upgrade to the version that is in the sample project and try again.

 

Thanks,

 

Edwin

Tags
DataForm
Asked by
Edwin
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Edwin
Top achievements
Rank 1
Share this question
or