microsoft / microsoft/microsoft-ui-xaml

DatePicker and DatePickerFlyout throw System.ArgumentException when using CalendarIdentifiers.Persian

Open
#11,236 3 comments 0 reactions 0 assignees View on GitHub
area-DateTimePickers bug team-Controls
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

DatePicker and DatePickerFlyout throw a System.ArgumentException when CalendarIdentifier is set to Windows.Globalization.CalendarIdentifiers.Persian.

Other calendar systems such as Gregorian and Hijri work correctly.

The Windows.Globalization.Calendar API itself successfully supports the Persian calendar, so the issue appears to be specific to the WinUI DatePicker and DatePickerFlyout controls.

### Why is this important?

The Persian calendar is an officially supported calendar system exposed by the Windows.Globalization API through CalendarIdentifiers.Persian.

However, WinUI 3's DatePicker and DatePickerFlyout throw a System.ArgumentException when this calendar identifier is used, making it impossible to use the built-in date picker with the Persian calendar.

This prevents developers from creating applications for Persian-speaking users using the native WinUI controls. As a result, developers must implement and maintain custom Persian date picker controls, even though the underlying Windows.Globalization API already supports the Persian calendar.

The behavior is also inconsistent because Windows.Globalization.Calendar works correctly with CalendarIdentifiers.Persian, while DatePicker and DatePickerFlyout do not.

### Steps to reproduce the bug

1. Create a new WinUI 3 project using Windows App SDK 2.2.0.
2. Add a DatePicker control or create a DatePicker instance in code.
3. Set the CalendarIdentifier to Windows.Globalization.CalendarIdentifiers.Persian.

Example:

```csharp
using Microsoft.UI.Xaml.Controls;
using Windows.Globalization;

var picker = new DatePicker
{
CalendarIdentifier = CalendarIdentifiers.Persian
};
```

Or:

```csharp
var flyout = new DatePickerFlyout
{
Date = DateTimeOffset.Now,
CalendarIdentifier = CalendarIdentifiers.Persian
};

flyout.ShowAt(MyButton);
```

4. Run the application.
5. Observe that a System.ArgumentException ("The parameter is incorrect.") is thrown.

Additional verification:

The following code works correctly:

```csharp
var calendar = new Windows.Globalization.Calendar();
calendar.ChangeCalendarSystem(CalendarIdentifiers.Persian);

Debug.WriteLine(calendar.Year);
Debug.WriteLine(calendar.Month);
Debug.WriteLine(calendar.Day);
```

This confirms that the Windows.Globalization API supports the Persian calendar, while DatePicker and DatePickerFlyout do not.

### Actual behavior

When the CalendarIdentifier property is set to Windows.Globalization.CalendarIdentifiers.Persian, the application throws a System.ArgumentException with the message:

"The parameter is incorrect."

The exception occurs during DatePicker initialization or when displaying a DatePickerFlyout.

The same code works correctly when using CalendarIdentifiers.Gregorian or CalendarIdentifiers.Hijri.

Additionally, Windows.Globalization.Calendar successfully supports CalendarIdentifiers.Persian, indicating that the issue is specific to the WinUI DatePicker and DatePickerFlyout controls.

### Expected behavior

When CalendarIdentifier is set to Windows.Globalization.CalendarIdentifiers.Persian, the DatePicker and DatePickerFlyout should initialize and function correctly, just as they do with Gregorian and Hijri calendars.

The control should display and allow selection of dates using the Persian calendar.

If the Persian calendar is not currently supported, the documentation should explicitly state this, or the control should throw a clear, meaningful exception instead of a generic System.ArgumentException ("The parameter is incorrect.").

### Screenshots

_No response_

### NuGet package version

Microsoft.WindowsAppSDK 2.2.0

### Windows version

Windows 11 (26H1): Build 28000

### Additional context

I verified that this issue is specific to the Persian calendar identifier.

Test results:

- ✅ CalendarIdentifiers.Gregorian works correctly.
- ✅ CalendarIdentifiers.Hijri works correctly.
- ❌ CalendarIdentifiers.Persian throws System.ArgumentException ("The parameter is incorrect.").

I also verified that the underlying Windows.Globalization API supports the Persian calendar correctly:

```csharp
var calendar = new Windows.Globalization.Calendar();
calendar.ChangeCalendarSystem(Windows.Globalization.CalendarIdentifiers.Persian);

Debug.WriteLine(calendar.Year);
Debug.WriteLine(calendar.Month);
Debug.WriteLine(calendar.Day);

Output:

```text
1405
4
23
```

This suggests that the issue is not related to Windows.Globalization.Calendar itself, but to the WinUI DatePicker/DatePickerFlyout implementation when using the Persian calendar identifier.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in a WinUI 3 project with Microsoft.WindowsAppSDK 2.2.0, using DatePicker and DatePickerFlyout with CalendarIdentifiers.Persian. Compare their behavior with Windows.Globalization.Calendar and the working Gregorian and Hijri cases. Done means both controls initialize, display, and allow selection of Persian-calendar dates without the ArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.