Getting started with .NET MAUI Date Time Picker (SfDateTimePicker)

4 Oct 20235 minutes to read

This section explains how to add the Date Time Picker control. It covers only the basic features needed to get started with Syncfusion Date Time Picker.

Creating an application using the .NET MAUI Date Time Picker

  1. Create a new .NET MAUI application in Visual Studio.

  2. Syncfusion .NET MAUI components are available on nuget.org. To add SfDateTimePicker to your project, open the NuGet package manager in Visual Studio, search for Syncfusion.Maui.Picker, then install it.

  3. To initialize the control, import the control namespace Syncfusion.Maui.Picker in XAML or C# code.

  4. Initialize SfDateTimePicker.

<ContentPage   
    . . .
    xmlns:picker="clr-namespace:Syncfusion.Maui.Picker;assembly=Syncfusion.Maui.Picker">

    <picker:SfDateTimePicker />
</ContentPage>
using Syncfusion.Maui.Picker;
. . .

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        SfDateTimePicker picker = new SfDateTimePicker();
        this.Content = picker;
    }
}

Register the handler

The Syncfusion.Maui.Core NuGet is a dependent package for all Syncfusion controls of .NET MAUI. In the MauiProgram.cs file, register the handler for Syncfusion core.

using Syncfusion.Maui.Core.Hosting;
namespace GettingStarted
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();

            builder.ConfigureSyncfusionCore();
            builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("Segoe-mdl2.ttf", "SegoeMDL2");
            });

            return builder.Build();
        }
    }
}

Date Time Picker header

The SfDateTimePicker control provides the default header which shows the current selected date and selected time.

In the SfDateTimePicker control, validation buttons (OK and Cancel) can be customized by setting the OkButtonText and CancelButtonText properties in the PickerFooterView. It allows you to confirm or cancel the selected date and time. The OkButtonText can be enabled using the ShowOkButton property in the PickerFooterView.

<picker:SfDateTimePicker x:Name="Picker">
    <picker:SfDateTimePicker.FooterView>
        <picker:PickerFooterView ShowOkButton="True" Height="40" />
    </picker:SfDateTimePicker.FooterView>
</picker:SfDateTimePicker>
SfDateTimePicker picker = new SfDateTimePicker();
picker.FooterView= new PickerFooterView()
{  
    ShowOkButton = true,
    Height = 40,
};

this.Content = picker;

Set Footer view in .NET MAUI Date Time picker.

Set height and width to the Date Time Picker

The SfDateTimePicker control allows you to change the height and width by using the HeightRequest and WidthRequest properties in the SfDateTimePicker.

<picker:SfDateTimePicker x:Name="Picker" 
                    HeightRequest="280" 
                    WidthRequest="300">
</picker:SfDateTimePicker>
SfDateTimePicker picker = new SfDateTimePicker()
{
    HeightRequest = 280,
    WidthRequest = 300,
};

this.Content = picker;

Set Height and Width in .NET MAUI Date Time picker.

Set selected date and selected time to the Date Time Picker

The SfDateTimePicker control allows you to select the date and time by using the SelectedDate property in the SfDateTimePicker. The default value of the SelectedDate is the current date and time.

<picker:SfDateTimePicker x:Name="Picker" 
                         SelectedDate="9/7/2023 10:15:22">
</picker:SfDateTimePicker>
SfDateTimePicker picker = new SfDateTimePicker()
{
    SelectedDate = new DateTime(2023, 09, 07, 10, 15, 22),
};

this.Content = picker;

Set selected date in .NET MAUI Date Time picker.