Forum Xamarin.Forms

Xamarin.Forms Android DatePicker/TimePicker button listener

Hikari91Hikari91 ITMember ✭✭✭

I need to know if a user tapped on the "cancel" or on the "ok" button
in a date/time picker of an Xamarin.Forms Android app.

I have tried to add a function to the Click event but this is never triggered.

This is my code (similar for the TimePicker):

using Android.Content;
using MyApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using MyApp.Models;
using Java.Util;

[assembly: ExportRenderer(typeof(DatePicker), typeof(DatePickerCustomRenderer))]

namespace MyApp.Droid {
    public class DatePickerCustomRenderer : DatePickerRenderer {

        public DatePickerCustomRenderer(Context context) : base(context) { } 

        protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e) {
            base.OnElementChanged(e);

            Locale locale = new Locale(Utente.FormatoPerDateTimePicker);
            Control.TextLocale = locale;

            Control.Click += Control_Click;
        }

        private void Control_Click(object sender, System.EventArgs e) {
            // This function is never called :(
            throw new System.NotImplementedException();
        }
    }
}

How can I do this?

Thank you!

Sign In or Register to comment.