TimePicker Rendered is crashed

SinghsumitSinghsumit INMember ✭✭

Hello xamarians, I want to customize timepicke but its crashed when I click ok button, I wrote this code

[assembly: ExportRenderer(typeof(CustomTimePicker), typeof(TMPickerRenderer))]
namespace MaterialDesignStyleApp.Droid
{
public class TMPickerRenderer : TimePickerRenderer
{
private TimePickerDialog dialog = null;
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
Control.SetTextColor(Android.Graphics.Color.Rgb(97, 187, 198));
Control.TextSize = 14;
Control.Click += Control_Click;
}

    void Control_Click(object sender, EventArgs e)
    {
        ShowTimePicker();
    }
    private void ShowTimePicker()
    {
        try
        {
            if (dialog == null)
            {
                Calendar c = Calendar.Instance;
                int hour = c.Get(CalendarField.HourOfDay);
                int minute = c.Get(CalendarField.Minute);
                dialog = new TimePickerDialog(Forms.Context, this, hour, minute, true);
            }
            dialog.Show();
        }
        catch (Exception ex)
        {
        }

    }

    public void OnTimeSet(TimePicker view, int hourOfDay, int minute)
    {
        var time = new TimeSpan(hourOfDay, minute, 0);
        this.Element.SetValue(TimePicker.TimeProperty, time);
       TimeSpan selectedTime = new TimeSpan(hourOfDay, minute, 00);
       Control.Text= time.ToString(selectedTime.ToString());// _timeSelectedHandler(selectedTime);
    }
}

}

Pls Help Me. :(

Sign In or Register to comment.