DateEditor throws exception on Android

7 posts, 0 answers
  1. Edwin
    Edwin avatar
    5 posts
    Member since:
    Apr 2016

    Posted 30 Dec 2016 Link to this post

    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.
  2. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    576 posts

    Posted 04 Jan Link to this post

    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
  3. Edwin
    Edwin avatar
    5 posts
    Member since:
    Apr 2016

    Posted 04 Jan in reply to Rosy Topchiyska Link to this post

    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.

     

  4. Edwin
    Edwin avatar
    5 posts
    Member since:
    Apr 2016

    Posted 04 Jan in reply to Edwin Link to this post

    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).
  5. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    576 posts

    Posted 09 Jan Link to this post

    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
  6. Edwin
    Edwin avatar
    5 posts
    Member since:
    Apr 2016

    Posted 09 Jan in reply to Rosy Topchiyska Link to this post

    Thank you for taking a look. I will try the sample project you provided and let you know.
  7. Edwin
    Edwin avatar
    5 posts
    Member since:
    Apr 2016

    Posted 10 Feb Link to this post

    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

Back to Top