---
title: "Add a date picker to a C# desktop or mobile app"
url: https://recursiveai.org/oneapp/cookbook/add-date-picker-to-csharp-app/
description: "Open a calendar from a button, read the selected date as a DateOnly in C#, and restrict which days users can pick with OneApp.Kit."
version: "1.2.1"
---

Bind a `DatePicker` to your C# model in `BookingPage.html`.

```shell
dotnet add package RecursiveAI.OneApp.Kit
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```html
<DatePicker Model="{Booking}"
  AriaLabel="Booking date" />
```

In `BookingPage.cs`, declare `public CalendarModel Booking { get; } = new();`.

[The example](https://recursiveai.org/oneapp/cookbook/add-date-picker-to-csharp-app/add-date-picker-to-csharp-app.zip) is the full program below: unzip it and `dotnet run`.

The button opens a month grid and shows the selected date when you pick a day.

## Full program

The zip includes `Demo.csproj`, a .NET 10 console project. If starting from a new console project, also add the app host and the template compiler:

```shell
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```
 To assemble the example by hand, put these three files beside the project file. The OneUI package compiles `BookingPage.html` into the other half of the `BookingPage` partial class.

`BookingPage.html` wraps the picker in the kit’s `Theme` and formats the selected date as year-month-day:

```html
<Theme>
  <main style="padding: 24px">
    <h1>Booking</h1>
    <DatePicker Model="{Booking}" AriaLabel="Booking date"
                TriggerId="booking" Placeholder="Pick a date"
                Format="yyyy-MM-dd" />
  </main>
</Theme>
```

`BookingPage.cs` keeps the selection in C# and sets a fixed “today” so the example always opens to December 2026:

```csharp
using System.Globalization;
using OneApp.Kit;

public partial class BookingPage
{
    public CalendarModel Booking { get; } = new()
    {
        Today = new DateOnly(2026, 12, 5),
        Culture = CultureInfo.GetCultureInfo("en-US"),
    };

    protected override void OnMounted()
    {
        Booking.ValueChanged += date =>
            Console.WriteLine($"Booking date: {date:yyyy-MM-dd}");
    }
}
```

`Program.cs` opens the window:

```csharp
using OneApp;

using var host = AppHost.Create(new AppOptions(new BookingPage())
{
    Title = "Booking",
    Width = 420,
    Height = 440,
});
host.Run();
```

Click **Pick a date**, then **8** in **December 2026**. The steps are the same on Windows and macOS (Apple silicon), but the output below was verified only on Linux. The calendar closes, the button reads **2026-12-08**, and the terminal prints:

```text
Booking date: 2026-12-08
```

If the compiler can’t find `Booking`, make sure the template and partial class are both called `BookingPage` and the project references `RecursiveAI.OneUI`.

![Booking window with the December 2026 calendar open](https://recursiveai.org/oneapp/images/add-date-picker-to-csharp-app/calendar.png)

## Variations

To show the calendar directly on the page instead of behind a button, replace the `DatePicker` with:

```html
<Calendar Model="{Booking}" Bordered="true" />
```

## Related recipes

- [Build a desktop app with HTML and CSS in C#](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Build a select dropdown in a C# desktop app](https://recursiveai.org/oneapp/cookbook/build-desktop-select-dropdown/)

## The short answer

In a OneApp desktop or mobile project, add the kit’s `DatePicker` to a OneUI template and pass in a C# `CalendarModel`. Read `Booking.Value` for the current selection or subscribe to `Booking.ValueChanged` to act when it changes. The type is `DateOnly?`: `null` means no day is selected. A booking day doesn’t need a time of day or a time zone; add those separately if you’re scheduling a specific appointment time. The same component goes in a mobile project; the zip runs as a desktop app, and the [mobile guide](https://recursiveai.org/oneapp/docs/mobile/) covers deploying to a phone.

## How do I set the minimum and maximum dates in a C# date picker?

Set `Min` and `Max` on the model, not on the picker. Add these lines to the initializer in `BookingPage.cs` to allow bookings from December 7 through December 11, inclusive:

```csharp
Min = new DateOnly(2026, 12, 7),
Max = new DateOnly(2026, 12, 11),
```

Days outside that interval are dimmed and can’t be chosen, even though you can still reach them with the arrow keys. The previous and next month buttons are disabled when the month they would open has no available dates. To rule out dates inside the interval as well, such as a holiday, use the model’s `Disabled` predicate. These rules control what the user can choose; they don’t replace checking availability again before saving a booking.

## How do I select a date with the keyboard?

Tab to the picker button and press Enter or Space to open it. The calendar focuses the chosen day, or today if there’s no selection. Use Left and Right to move a day, Up and Down to move a week, and Page Up and Page Down to switch months. Enter or Space picks the focused day. In single-date mode, picking a day closes the calendar and returns focus to the button. Escape also closes it, without changing the selection.

Use `AriaLabel` to name the button by purpose, such as “Booking date.” The label stays useful both before and after the visible button text changes. The [date picker docs](https://recursiveai.org/oneapp/docs/kit/#dates) describe the grid’s accessibility roles, range selection, and how the model’s culture sets month names and the first day of the week.
