MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Persian calendar months and years problem.

Open jamalhosseini opened this issue 5 years ago • 8 comments

This issue #1077 was posted and based on #1080 and this problem should be solved, but it was not. there are Calendar header translated to persian calendar but Calendar body is Gregorian yet. I set the Language property as persian and Flow direction as RightToLeft but not effected on result, add startup codes also.

see: this screenshot

Pay attention to screenshot Red zone are persian but Yellow zone is Gregorian. On Yellow zone year is 1398 and day is "پنجشنبه 17 بهمن" is 17/11/1398, but calendar day is 6/2/2020.

also on below screenshot applies for months and years, 2020 must be 1398.

https://www.dropbox.com/h?preview=Untitled.pngq.png

jamalhosseini avatar Feb 08 '20 08:02 jamalhosseini

@Keboo @jamalhosseini Any news?

Lorymi avatar Nov 08 '20 09:11 Lorymi

This Problem does not resolved yet 😢

@Keboo

Reza-Noei avatar Jan 08 '21 15:01 Reza-Noei

The screenshots are removed. Could you please explain in text which behaviour is preferred?

MichelMichels avatar Dec 24 '21 15:12 MichelMichels

I did what is written in the startup event https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MainDemo.Wpf/App.xaml.cs#L30

And I have a Persian Calendar that looks good. There is just the date format which is not good. This one uses the computer culture (french in my case). image

There is not this problem when using the CultureInfo en-US image

ElieTaillard avatar Apr 27 '22 13:04 ElieTaillard

hi guys i'm having the same problem and it seems the bug is not resolved yet . any news?

Solia-R avatar Feb 24 '23 09:02 Solia-R

@Xaalek and @Solia-R So what I believe is happening here is that you/we are stumbling upon a limitation within the WPF base class library. In WPF, the calendar - to my knowledge - really only supports Gregorian calendars (in the screenshots above you can also see this; the language has changed to Farsi, but the calendar remains a Gregorian one which works, but is a bug/limitation in WPF).

In short, I don't believe this is an issue in MDIX, but rather a general WPF issue.

If you dig into the WPF source code, you will see that the DatePicker tries to resolve a DateTimeFormatInfo based on the Language property; falling back to CultureInfo.CurrentCulture if not found: https://source.dot.net/#PresentationFramework/System/Windows/Controls/DatePicker.cs,1003 https://source.dot.net/#PresentationFramework/System/Windows/Controls/DateTimeHelper.cs,110

To actually resolve the DateTimeFormatInfo, it uses the internal DateTimeHelper which tries to resolve a calendar for the provided CultureInfo. However, this internal method only looks for Gregorian calendars, and therefore I don't believe it will ever pick the correct format for Farsi (or Arabic for that matter). https://source.dot.net/#PresentationFramework/System/Windows/Controls/DateTimeHelper.cs,125

I could be wrong about this, but I seem to recall running into this on some projects I worked on without ever getting it solved properly.

@Keboo Is this something you have seen before? And were you able to solve it?

nicolaihenriksen avatar Feb 24 '23 16:02 nicolaihenriksen

We have looked into this before, unfortunately I believe you are correct. The DatePicker control is documented to only support the Gregorian calendar. Outside of rolling our own calendar control to support it, I don't think there is a simple way to support the Persian calendar.

Keboo avatar Feb 26 '23 05:02 Keboo

rolling our own calendar control to support it

Yikes, that does not sound like an easy job. Although I feel a have a descent level of experience and expertise, messing around with calendars, time zones, DST, date formats and the like, always turns out to be way more complicated that I would have foreseen. There are so many quirks and nitty gritty details to be aware of.

nicolaihenriksen avatar Feb 28 '23 09:02 nicolaihenriksen