StringFormat Localization issues in wpf

Viewed 50695

In WPF 3.5SP1 i use the last feature StringFormat in DataBindings:

     <TextBlock Text="{Binding Path=Model.SelectedNoteBook.OriginalDate, StringFormat='f'}"
                FontSize="20" TextTrimming="CharacterEllipsis" />

The problem I face is that the date is always formatted in English...although my system is in French ? How can i force the date to follow system date?

9 Answers
// Ensure the current culture passed into bindings is the OS culture.
// By default, WPF uses en-US as the culture, regardless of the system settings.
FrameworkElement.LanguageProperty.OverrideMetadata(
      typeof(FrameworkElement),
      new FrameworkPropertyMetadata(
          XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

From Creating an Internationalized Wizard in WPF

If you are working on code rather than XAML, you can set the ConverterCulture as follows:

binding.ConverterCulture = System.Globalization.CultureInfo.CurrentCulture;

Kudos to @KZeise for pointing out the subtle difference between using the default culture definition and using the user's customized culture definition.

Related