4

The work around...

FrameworkElement.LanguageProperty.OverrideMetadata(
 typeof(FrameworkElement), 
 new FrameworkPropertyMetadata(
  XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

...used to work till now (mentioned here: StringFormat Localization issues in wpf).

Instead till I ported my application from 3.5SP1 to 4.0, it was working. But now in 4.0 it stopped working again. Anybody experiencing this?

EDIT: It is now not even working in 3.5SP1. I think this has something to do with the installation of 4.0 as previously this was working.

It is not working by either adding the workaround or removing it. I even tried adding...

CultureInfo.CurrentCulture.ClearCachedData();
this.Language = XmlLanguage.GetLanguage( CultureInfo.CurrentCulture.IetfLanguageTag);

to Window constructor. This also didn't worked.

Community
  • 1
  • 1
Yogesh
  • 14,498
  • 6
  • 44
  • 69

1 Answers1

0

1. Make sure you are overriding default value of LanguageProperty as early as possible. App's static constructor is the best bet. This is important because BindingExpression caches value of this property and does not reevaluate it afterwards for performance reasons.

2. What is your CultureInfo.CurrentCulture? Are you sure it's the one you expect to see?

3. Overriding Language property metadata has no effect if you you specify xml:lang attribute somewhere upper in the tree. E.g. if you say:

<StackPanel xml:lang="it">
  <TextBlock Text="{Binding StringFormat=C}"/>
</StackPanel>

You'll get Italian currency no matter what you set in property metadata.

4. Overriding Language property metadata has no effect if you specify ConverterCulture property in binding. E.g. if you say: <TextBlock Text="{Binding StringFormat=C, ConverterCulture=ja}"/> you'll get Japanese currency no matter what you set either in property metadata or in xml:lang attribute.

This behavior was not changed between frameworks as far as I know.

Hope this helps

Anvaka
  • 15,658
  • 2
  • 47
  • 56