我正在研究跨所有語言(共4個)應具有相同NumberFormat和DateTimeFormat的多語言應用程序。 我覺得最好的方法是隻設置一次這些格式,而不是每次將值轉換爲字符串,因爲這可能會遺忘某些值並導致錯誤。用於多語言UWP應用程序的自定義NumberFormat
在Silverlight應用程序,這是可以實現的方式如下:
var cultureInfo = new CultureInfo(languageCode);
cultureInfo.NumberFormat.NumberGroupSeparator = " ";
cultureInfo.NumberFormat.NumberDecimalDigits = 2;
cultureInfo.NumberFormat.NumberDecimalSeparator = ",";
cultureInfo.DateTimeFormat.ShortDatePattern = "dd'/'MM'/'yyyy";
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
由於Thread.CurrentThread.CurrentCulture
不再可用,我使用CultureInfo.CurrentCulture
代替。 不幸的是,通過使用此方法,customInfo似乎並未在整個應用程序中設置。我在OnLaunched
方法中設置了文化,所以我認爲它設置在正確的線程上。
我知道,自WinRT以來,應用程序只能運行在應用程序有資源的文化之一,但這是否意味着我們不能再覆蓋NumberFormat?或者有更好的方法來達到我想要的結果嗎?
這是你的答案,這是從Github描述複製粘貼的另一個。 – Ian
使用源代碼進行更新 –