MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.09k stars 3.42k forks source link

Persian calendar months and years problem. #1646

Open jamalhosseini opened 4 years ago

jamalhosseini commented 4 years ago

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

Lorymi commented 3 years ago

@Keboo @jamalhosseini Any news?

Reza-Noei commented 3 years ago

This Problem does not resolved yet 😢

@Keboo

MichelMichels commented 2 years ago

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

ElieTaillard commented 2 years ago

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

Solia-R commented 1 year ago

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

nicolaihenriksen commented 1 year ago

@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?

Keboo commented 1 year ago

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.

nicolaihenriksen commented 1 year ago

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.