How to handle date changed using the DateSelected event

28 Jan 20212 minutes to read

You can perform an operation when selecting a date using the DateSelected event. The DateSelected event returns the following arguments:

Members Description
NewValue Shows recently selected date in DatePicker.
OldValue Shows previously selected date in DatePicker.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DatePickerSample"
             xmlns:syncfusion="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"
             x:Class="DatePickerSample.MainPage">
    <ContentPage.Content>
        <syncfusion:SfDatePicker x:Name="datepicker"
                                 DateSelected="Datepicker_DateSelected"/>
    </ContentPage.Content>
</ContentPage>
using Syncfusion.XForms.Pickers;
using Xamarin.Forms;

namespace DatePickerSample
{
    public partial class MainPage : ContentPage
    {
        SfDatePicker datePicker;
        public MainPage()
        {
            InitializeComponent();
            datePicker = new SfDatePicker();
            datePicker.DateSelected += Datepicker_DateSelected;
            this.Content = datePicker;
        }

        private void Datepicker_DateSelected(object sender, Syncfusion.XForms.Pickers.DateChangedEventArgs e)
        {
            DisplayAlert("DateChanged", "NewDate: " + e.NewValue + "\n" + "OldDate: " + e.OldValue, "Ok");
        }
    }
}

MinimumDate of SfDatePicker