Selection in .NET MAUI Date Time Picker (SfDateTimePicker)
18 Nov 20182 minutes to read
Set the selected date and time
The SfDateTimePicker control lets you select a date and time using the SelectedDate property of the SfDateTimePicker. The default value of SelectedDate is the current date and time.
<ContentPage
. . .
xmlns:picker="clr-namespace:Syncfusion.Maui.Picker;assembly=Syncfusion.Maui.Picker">
<picker:SfDateTimePicker x:Name="picker"
SelectedDate="9/7/2023 10:15:22">
</picker:SfDateTimePicker>
</ContentPage>using Syncfusion.Maui.Picker;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfDateTimePicker picker = new SfDateTimePicker()
{
SelectedDate = new DateTime(2023, 09, 07, 10, 15, 22),
};
this.Content = picker;
}
}
Clear selection
The SfDateTimePicker provides a clear selection feature that allows users to clear the selected date and time by setting the SelectedDate property to null.
<ContentPage
. . .
xmlns:picker="clr-namespace:Syncfusion.Maui.Picker;assembly=Syncfusion.Maui.Picker">
<picker:SfDateTimePicker x:Name="picker" />
</ContentPage>using Syncfusion.Maui.Picker;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.picker.SelectedDate = null;
}
}