1

here is my scenario. i build xamarin forms app. when the user device language is English it works fine..but in Arabic language . any page he open that contains DatePicker or datetime the app crashes ..any help please.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Ahmed Omer
  • 43
  • 1
  • 4
  • Different from other countries and regions, Arabic writing is oriented from right to left. So you should make your app to support Internationalization.Refer to the link https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/. – Lucas Zhang Jan 18 '19 at 00:41
  • @LucasZhang-MSFT for your reference https://github.com/xamarin/xamarin-android/issues/2511 – Access Denied Aug 24 '20 at 02:30

2 Answers2

9

This is a known Xamarin bug, which they unable to fix since I reported it in 2015. In brief linker thinks that you don't need Other calendars rather than default. Even though the project settings specify that it supports these languages. In order to workaround it create calendars in your code. (Force linker to include them) And call it from AppDelegate.cs or from other Famarin Forms app init method:

private static void PreventLinkerFromStrippingCommonLocalizationReferences()
{
        _ = new System.Globalization.GregorianCalendar();
        _ = new System.Globalization.PersianCalendar();
        _ = new System.Globalization.UmAlQuraCalendar();
        _ = new System.Globalization.ThaiBuddhistCalendar();
}

https://github.com/xamarin/xamarin-android/issues/2511

Access Denied
  • 8,723
  • 4
  • 42
  • 72
0

Try specifying a locale when using the date value from the image picker

               var dateFormatter = new NSDateFormatter
                {
                    DateFormat = _dateFormatString
                };

                var enLocale = new NSLocale("en_US");
                dateFormatter.Locale = enLocale;

                sender.Text = dateFormatter.ToString(modalPicker.DatePicker.Date);
Pooja Kamath
  • 1,290
  • 1
  • 10
  • 17
  • This will cause all of your strings to be displayed in the unusual USA format of MM/DD/YYYY. (Most of the world orders by increasing/decreasing significance.) – idbrii Nov 19 '20 at 19:35