I created a value converter in my Windows Phone 7 ...
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// ...
}
// ...
}
... and use it like this ...
<TextBlock Text="{Binding SomeField, Converter={StaticResource MyConverter}, ConverterParameter=SomeParameter}" <!-- ... --> />
My problem: The argument
culture of the Convert method is always "en-US", even when I change the culture of the Windows Phone device (or emulator) say to german Germany, the culture
argument stays english.
Not a bug, intended behaviour. See this post on MSConnect WPF Binding uses the wrong CurrentCulture by default.
The solution is to set the Language
property of your PhoneApplicationPage
to the CurrentCulture, like this:
Language = XmlLanguage.GetLanguage(
Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName);
Or alternatively specify the culture in XAML, using the Language
attribute, like this:
<TextBlock Language="de-DE" Text="..." />
Or on the PhoneApplicationPage
it self
<phone:PhoneApplicationPage Language="de-DE" ...
But a much better solution is not to have a value-converter that's depending on the culture
argument.
Edit: I blogged about a alternative solution: DateTime formatting in a ValueConverter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With