StringFormat Localization issues in wpf

jonathan picture jonathan · Feb 6, 2009 · Viewed 47.1k times · Source

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?

Answer

loraderon picture loraderon · Feb 6, 2009
// 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