Bug 58666 - Date Picker and Time Picker Crash in Android
Summary: Date Picker and Time Picker Crash in Android
Status: RESOLVED DUPLICATE of bug 58665
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-08-09 12:10 UTC by Ojas Teredesai
Modified: 2017-08-09 13:16 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 58665

Description Ojas Teredesai 2017-08-09 12:10:16 UTC
We are using the date and time picker in our Xamarin Application and based on our application requirement we have to customize it to make change in its opening behavior. So we have used Renderer of both controls but it works perfectly on iOS platform but application gets crashed on Android with error 'element is not of type Xamarin.Forms.TimePicker Parameter name: element a'. for more detail error please find the attached Screen Shorts.
 
Because of above issue we are blocked to deliver our next task to QA team.
 
We are using below code for Android Render which causes application crash:
 
namespace Zerochaos.Mobile.UI.Droid.Renderers
{
    public class ZCTimePickerRenderer:TimePickerRenderer
    {
        public ZCTimePickerRenderer()
        {
        }
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.TimePicker> e)
        {
            base.OnElementChanged(e);

            //this.Control.SetTextColor(Android.Graphics.Color.Green);
        }

    }
}
 
 
 
Below code we are using for iOS render and its working fine.
 
public class CustomeTimePickerRenderer:TimePickerRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
        {
            base.OnElementChanged(e);

            CustTimePicker timePickerobj = (CustTimePicker)Element;

            if (timePickerobj != null)
            {
                SetBorderStyle(timePickerobj);
                SetTextColor(timePickerobj);

                Control.AdjustsFontSizeToFitWidth = true;
            }

            if (e.OldElement == null)
            {
                //Wire events
            }

            if (e.NewElement == null)
            {
                //Unwire events
            }

            var toolbar = new UIToolbar(new CoreGraphics.CGRect(0.0f, 0.0f, Control.Frame.Size.Width, 44.0f));

            toolbar.Items = new[]
            {

                 new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Plain, delegate {  Control.ResignFirstResponder();

                    MessagingCenter.Send<MessageClass>(new MessageClass("cancel"),"Not update");
                   // this.Control.sele
                }),
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
               // new UIbar("Done", UIBarButtonItemStyle.Plain,),
                 new UIBarButtonItem("Done", UIBarButtonItemStyle.Plain, delegate {  Control.ResignFirstResponder();
                 MessagingCenter.Send<MessageClass>(new MessageClass("done"),"Not update");

                })



            };



            this.Control.InputAccessoryView = toolbar;

            if (this.Control != null)
            {
                this.Control.Layer.BorderWidth = 0;
                //this.Control.Layer.BorderColor = App.HowlOutBackground.ToCGColor();
                this.Control.TextAlignment = UITextAlignment.Left;
            }

        }

        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (Control == null)
            {
                return;
            }

            CustTimePicker timePickerobj = (CustTimePicker)Element;

            if (e.PropertyName == CustTimePicker.TextColorProperty.PropertyName)
            {
                this.Control.TextColor = timePickerobj.TextColor.ToUIColor();
            }
        }

        void SetBorderStyle(CustTimePicker timePickerobj)
        {
            this.Control.BorderStyle = UIKit.UITextBorderStyle.None;
            //this.Control.BorderStyle = (datePicker.HasBorder == true) ? UIKit.UITextBorderStyle.RoundedRect : UIKit.UITextBorderStyle.None;

        }

        void SetTextColor(CustTimePicker timePickerobj)
        {
            this.Control.TextColor = timePickerobj.TextColor.ToUIColor();
        }

        void setFontSize(CustTimePicker timePickerobj)
        {

        }

    }
}
Comment 1 Paul DiPietro [MSFT] 2017-08-09 13:16:53 UTC

*** This bug has been marked as a duplicate of bug 58665 ***