Datepicker does not trigger date picker by default in xamarin.forms - Android

When using the DatePicker in xamarin.Forms, I am having difficulty finding out if the user has actually selected the default date or the datepicker just shows the default date I specified. Since the datepicker DateSelected event only fires when the datepicker field changes, I want to get the date from the datepicker only if the user actually selects the date.

How can I achieve this? Please comment if the issue has not been properly informed.

+3


source to share


2 answers


The Xamarin.Forms DatePicker.Date property can be set to a specific date or left alone and populated with the current date.

The DatePicker displays the no property to determine if the user selects a date or not.

To keep track of whether the user selects a date, you will have to track this yourself in the DateSelected event handler by setting some other variable that you can then query later to determine if it is a user-selected date. For example: -

objDatePicker.DateSelected+=((o2,e2)=>
{
blnIsUserSelectedANewDateThanDefault = true;
});

      

Note. However, if the user pops out a DatePicker and select the date the same as shown, it will not strong> DateSelected as the value is not .



Update 1: -

Unable to connect to Cancel button displayed with Xamarin.Forms DatePicker (v1.2.3x),

However, you can create your own renderer that achieves what you want to do.

If you go down this route, you can connect to the Cancel click that is displayed on the Android DatePickerDialog shown in the picture.

Once this event is detected in the custom renderer , you can set a flag or raise an event to indicate that the user has canceled dates.

0


source


Here are my findings:

Android:

SelectedDateChanged = Only triggered when the date has actually changed. triggered and canceled

SelectedDate = sets property to done and cancels unfocused = fires and cancels



IOS:

selecteddatechanged = fires every time you change date no matter what you did and cancel

SelectedDate = sets property to done and cancels unfocused = fires on completion and cancels For me, this makes the control almost unusable in my project. How can I tell if the user hit or just clicked the background to cancel the operation?

0


source







All Articles