Search code examples
c#xamarin.androiddatepickerdialog

Showing current date onwards in DatePickerDialog (Xamarin Android C#)


I am currently working on a capstone project and my professor wants me to restrict the previous date that has passed. Whenever I click my DatePickerDialog it starts with 1900, so the plan is to show the current date and onwards. For example today is 11/22/2022 then the DatePickerDialog should prompt the said date and onwards.

private void EventpickdateButton_Click(object sender, EventArgs e)
        {
            DatePickerDialog datePickerDialog = new DatePickerDialog(this.Activity, this, year, month, day);
            datePickerDialog.Show();
        }

Should I put a custom method in order to show the current date and onwards? I have searched for several sources but people usually use Xamarin.Forms and Android Studio(JAVA).


Solution

  • public override Dialog OnCreateDialog(Bundle savedInstanceState)
    {
        datePickerDialog.DatePicker.MinDate = Java.Lang.JavaSystem.CurrentTimeMillis(); // https://stackoverflow.com/a/38405851/109941 2022-11-21
    }