how to restrict previous dates in xamarin syncfusion sfpicker

hello,

how to restrict previous dates in xamarin syncfusion sfpicker DatePicker
or set default date as today in the sfpicker DatePicker

1 Reply 1 reply marked as answer

SP Sakthivel Palaniyappan Syncfusion Team February 22, 2021 08:53 AM UTC

Hi Shraddha,

Greetings from Syncfusion.

We have analyzed your query and we can achieve your requirement of “Set default date as today date” by setting SelectedItem property of SfPicker as like below code snippet.

XAML:

 
<picker:CustomDatePicker 
            x:Name="date" 
            ColumnHeaderHeight="40" 
            HorizontalOptions="Center" 
            PickerHeight="400" 
            PickerMode="Dialog" 
            PickerWidth="300" 
            SelectedItem="{Binding StartDate}" 
            VerticalOptions="Center" /> 

ViewModel:

 
    public ObservableCollection<object> StartDate 
    {​​​​​​​ 
            get {​​​​​​​ return _startdate; }​​​​​​​ 
            set {​​​​​​​ _startdate = value; RaisePropertyChanged("StartDate"); }​​​​ 
     } 
 
    public DatePickerViewModel() 
    {​​​​​​​ 
        ObservableCollection<object> todaycollection = new ObservableCollection<object>(); 
 
        //Select today dates 
        todaycollection.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Date.Month).Substring(0, 3)); 
        if (DateTime.Now.Date.Day < 10) 
            todaycollection.Add("0" + DateTime.Now.Date.Day); 
        else 
            todaycollection.Add(DateTime.Now.Date.Day.ToString()); 
        todaycollection.Add(DateTime.Now.Date.Year.ToString()); 
 
        this.StartDate = todaycollection; 
    }​​​​​​​ 

We h
ave created sample based on this and please find the sample from below.

Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/DatePickerDefaultTIme-802388784.zip

We have SfDatePicker control also for select the dates, please refer more details about SfDatePicker. By default it will take the today date as default date.

Document link:
https://help.syncfusion.com/xamarin/datepicker/overview

Please let us know if you have any other queries.

Regards,
Sakthivel P.
 


Marked as answer
Loader.
Up arrow icon