Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Disable dates in datepicker

AishwaryaKAishwaryaK INMember ✭✭

How to disable(cannot access) previous dates from today's date in datepicker. Please help me the answer.

Best Answer

Answers

  • VarunBabuSVarunBabuS INMember ✭✭✭

    hi @AishwaryaK

    set the mindate first that is the date from which picker should be enabled
    DateTime MinDate = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);//this basically should be current date

    now set mindate property of datepicker from where it should start

    DatePicker StartDatePicker = new DatePicker
    {
    Format = "dd/MM/yyyy",
    MinimumDate = MinDate,
    };

    Hope this might help...

  • VenkataSwamyVenkataSwamy INMember ✭✭✭✭
    edited June 2017

    Hi @AishwaryaK

    Datepicker having MinimumDate and MaximumDate properties we can set directly like below

    XAML:

           <DatePicker
                x:Name="pickerNotificationDate"
                Date="{Binding PropertyDate}"
                MinimumDate ="{Binding PropertyMinimumDate}"
                MaximumDate = "{Binding PropertyMaximumDate}">
    

    ViewModel Constructor

            PropertyMinimumDate = DateTime.Now;
            PropertyMaximumDate=DateTime.Now.AddDays(20);
    

    (Or)

    In C#

          DatePicker datePicker = new DatePicker();
          datePicker.MinimumDate = DateTime.Now;
    
  • hrithickhrithick Member ✭✭
    How to disable Saturday’s and Sunday’s?
Sign In or Register to comment.