DatePicker with date range

Hi all,
I have some questions about using SfPicker to achieve the DatePicker
1. I want the order of date picker selection is [Year, Month, Day] (like the pic below)
2. How to assign the picker a start date and end date to show?
3. I want to set the date picker with a specific date(of course the date is in the date range), how to do it?
4. How to get each of the values when the user changes the date?
5. I have 3 different SfPicker. How to identify which is pressed with the OK button? (when the OK button is pressed, 3 SfPicker all call to "picker_OkButtonClicked()')

private void picker_OkButtonClicked(object sender, Syncfusion.SfPicker.XForms.SelectionChangedEventArgs e)
{
//How to identify which picker activates this function?
}


https://www.syncfusion.com/xamarin-ui-controls/xamarin-datepicker

Thanks for your kindly response.

4 Replies 1 reply marked as answer

AS Anandraj Selvam Syncfusion Team January 27, 2021 01:44 AM UTC

Hi HannahC, 

Greetings from Syncfusion. 

We are currently validating on this and we will update the details on January 28, 2021. We appreciate your patience until then. 

Regards, 
Anand Raj S. 



RS Ruba Shanmugam Syncfusion Team January 28, 2021 09:45 AM UTC

Hi HannahC,

Thanks for your patience.

We have checked the reported query and we suggest you to use SfDatePicker to achieve your requirement.

Query 1: I want the order of date picker selection is [Year, Month, Day] (like the pic below)

We have `Format` API to represent the value of the date in a different string format and set date by using the Date property.

Query 2: How to assign the picker a start date and end date to show?

We can provide an option to select a date value within a specified range by using the MinimumDate and MaximumDate properties.

Query 3: I want to set the date picker with a specific date(of course the date is in the date range), how to do it?

You can set the specific date by using Date property.

Query 4: How to get each of the values when the user changes the date?

We can retrieve the selected date in the DateSelected event.

Query 5: I have 3 different SfPicker. How to identify which is pressed with the OK button? (when the OK button is pressed, 3 SfPicker all call to "picker_OkButtonClicked()')

You can get the picker when the Ok button is clicked using the StyleId API when the object name is set for the picker. Can you refer below user guidance for more information.

UG link: https://help.syncfusion.com/xamarin/datepicker/date-restriction

Please find the sample below.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DatePicker_Sample295351847

Please let us know, if you have any other concerns.

Regards,
Ruba Shanmugam


Marked as answer

HA HannahC January 29, 2021 08:33 AM UTC

Hi Ruba,
Thank you for the reply!
By following your advice to use sfDatePicker package, unfortunately, I encounter a problem.
I know the way to get the selected value of the DateTime is to call DateSelected() to get the NewValue.
Here, I want to make a revise to the action to get the value.
The default way is when I changing the date then I can get the value in the DateSelected function. 
What I want is to get the datetime by pressing the OK button in the footer and then close the sfDatePicker automatically.
Is there any way to achieve it?

Thanks for the kind response.

reference: https://help.syncfusion.com/xamarin/datepicker/customizations?cs-save-lang=1&cs-lang=csharp


RS Ruba Shanmugam Syncfusion Team January 29, 2021 08:39 AM UTC

Hi HannahC,

Greetings from Syncfusion.

We have validated your query and we would like to let you know that you can get the DateChangedEventArgs in OkButtonClicked event. Please refer the below sample and code snippet.

Code Snippet: 
  
XAML: 
<picker:SfDatePicker x:Name="datePicker"
                                      PickerWidth="300"
                                      PickerHeight="300"
                                      PickerMode="Dialog"
                                      ShowFooter="True"
                                      OkButtonClicked="SfDatePicker_OkButtonClicked"/>

XAML.cs:

private void SfDatePicker_OkButtonClicked(object sender, Syncfusion.XForms.Pickers.DateChangedEventArgs e)
{
          DisplayAlert("Notification", "SelectedItem" + e.NewValue.ToString(), "Ok");
 
  
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DatePickerEvents-1594379228

Please let us know, if you have any other concerns.

Regards,
Ruba Shanmugam 


Loader.
Up arrow icon