Selection
The DatePicker control enables the application users to quickly and easily select a date value by providing an API related to date selection.
Date Property
The Date
(DateTime?
) property defines the current date selection. Its default value is null
.
The following example demonstrates how to set the Date
property.
<telerik:RadDatePicker Date="2020,05,15"
SpinnerFormat="yyy-MMM"/>
In addition to this, you need to add the following namespace:
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
Clear Button
You can enable a Clear button which can be used to quickly remove the selected value. To enable the button, set IsClearButtonVisible
property of the DatePicker:
<telerik:RadDatePicker Date="2020,05,15"
IsClearButtonVisible="True" />
Methods
The DatePicker for .NET MAUI allows you to clear the selected date through its ClearSelection
method:
<StackLayout>
<Button Text="Clear Selection" Clicked="OnClearSelectionClicked"/>
<telerik:RadDatePicker x:Name="datePicker"/>
</StackLayout>
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
ClearSelection
inside the button click
event. As a result, the Date
property will be updated to null
.
private void OnClearSelectionClicked(object sender, EventArgs e)
{
this.datePicker.ClearSelection();
}
Events
The DatePicker exposes a SelectionChanged
event, which is raised when the user picks a date value.
The following example demonstrates how to use SelectionChanged
.
<telerik:RadDatePicker SelectionChanged="RadDatePicker_SelectionChanged"/>
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
SelectionChanged
event, where the sender
is the RadDatePicker
instance.
private void RadDatePicker_SelectionChanged(object sender, EventArgs e)
{
// implement your logic here
}