New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI DateTimePicker Commands

Telerik UI for .NET MAUI DateTimePicker exposes a number of commands for programmatic manipulation of its popup rendering.

DateTimePicker Commands

The DateTimePicker supports the following commands, which enable you to control the display of its popup and clear the selected date:

  • ToggleCommand(ICommand)—Allows you to show or hide the popup that is used for selecting a date value.
  • ClearCommand(ICommand)—Allows you to clear the displayed date.

The following example demonstrates how to set ToggleCommand and ClearCommand.

<VerticalStackLayout>
    <Button Text="Toggle Command" Command="{Binding Source={x:Reference dateTimePicker}, Path=ToggleCommand}"/>
    <Button Text="Clear Command" Command="{Binding Source={x:Reference dateTimePicker}, Path=ClearCommand}"/>
    <telerik:RadDateTimePicker x:Name="dateTimePicker" />
</VerticalStackLayout>

Add the following namespace:

PopupSelector Commands

Through the popup users can pick a date. The date value has to be confirmed or rejected with the OK or Cancel buttons that are located on the popup.

The DateTimePicker allows you to add a custom logic for the Accept and Cancel commands which are executed when the OK or Cancel buttons are clicked.

  • AcceptCommand(ICommand)—Defines the command, which confirms the current selection of the picker and closes the popup.
  • CancelCommand(ICommand)—Defines the command, which rejects the current selection of the picker and closes the popup.

You can apply the Accept and Cancel commands can by using the SelectorSettings property of DateTimePicker.

  1. Define the control and add the commands.

    <StackLayout>
      <telerik:RadDateTimePicker>
          <telerik:RadDateTimePicker.PopupSettings>
              <telerik:PickerPopupSettings AcceptCommand="{Binding Accept}"
                                           CancelCommand="{Binding Cancel}"/>
          </telerik:RadDateTimePicker.PopupSettings>
              <telerik:RadDateTimePicker.BindingContext>
                  <local:ViewModel/>
              </telerikInput:RadDateTimePicker.BindingContext>
      </telerik:RadDateTimePicker>
    </StackLayout>
    
  2. Set the ViewModel.

    public class ViewModel
    {
    public ICommand Accept { get; set; }
    public ICommand Cancel { get; set; }
    
    public ViewModel()
    {
        this.Accept = new Command(this.OnAccept);
        this.Cancel = new Command(this.OnCancel);
    }
    
    private void OnAccept(object obj)
    {
        // implement your custom logic here
    }
    
    private void OnCancel(object obj)
    {
        // implement your custom logic here
    }
    }
    
  3. Add the following namespace:

    xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
    

    See Also

In this article
Not finding the help you need?