How can I force Localization Culture to en-US for whole applicaiton in Xamarin

Stephan Ronald picture Stephan Ronald · Oct 7, 2015 · Viewed 20.1k times · Source

How to force Xamain - Android / iOS to work in US English culture regardless of user setting. The issue I am facing in my application is, The app only support US/UK English, But if the user changes the langue preference to Spanish , German etc. The number date etc format will change.

For Example, 2.35 will represent in Spanish, German as 2,35.

So if the user try to use the application with similar language, the app will miss behave or crash. Crash will occur in situation like when I try for Convert.ToDouble("2,35"); or similar.

So my doubt is,

Is it possible in Xamarin to forcefully set the culture as en-US. May be in one place, otherwise I need to change it all the places I performing Conversion.

Please help.

Answer

7vikram7 picture 7vikram7 · Apr 18, 2017

I am working with a Xamarin Forms App.

Setting the Culture in the App Class did the trick for me.

using System.Globalization;
using System.Threading;


private void SetCultureToUSEnglish()
{
    CultureInfo englishUSCulture = new CultureInfo("en-US");
    CultureInfo.DefaultThreadCurrentCulture = englishUSCulture;
}