Xamarin DataPicker how to handle done button click event

3.4k Views Asked by At

I added to my DataPicker unfocused event. And in this event I would like to check if Done button was clicked.

private void DatePicker_Unfocused(object sender, FocusEventArgs e)
        {

        }

Or other option. Is it possible to add listener to button Done, and if was clicked then fired some method?

How can I do it? Thank you.

1

There are 1 best solutions below

3
MalokuS On

Every UI control which receives input always has some event handlers which you can listen to.

In your case the DatePicker has an Event Handler which fires when the Date property changes.

Here is the documentation: DatePicker Event Handler - Xamarin Documentation

The implementation of this handler is simple:

DatePicker datePicker;
DateTime newDate;
DateTime oldDate;

public YourPage()
{
    datePicker.DateSelected += Date_DateSelected;
}

void Date_DateSelected(object sender, DateChangedEventArgs e)
{
    newDate = e.NewDate;
    oldDate = e.OldDate;
}

Always read the documentation first, as that's the best way to learn how to use a specific control.