to StackOverflow
to StackOverflow

Reputation: 124776

Best way to set CurrentCulture so it applies to all WPF components

I've just learnt to my surprise that WPF doesn't use the CurrentCulture for bindings, instead defaulting to en-US.

In a pure WPF application, this can be fixed in one place by setting the language globally once in the App class.

However I have a WinForms application that is being progressively migrated to WPF, and contains several WPF UserControls. What's the best/simplest way to ensure the CurrentCulture is used for all UserControls? Do I really have to make all my UserControls inherit from a base class that does this, or is there some way to set it globally?

Upvotes: 1

Views: 799

Answers (2)

Thomas Levesque
Thomas Levesque

Reputation: 292615

You can still use the same approach with LanguageProperty.OverrideMetadata, just put it at the beginning of your program (Main method).

Upvotes: 1

Rick Sladkey
Rick Sladkey

Reputation: 34250

You can use a slightly different approach and derive once from ElementHost and manipulate your WPF UserControl instances as they are instantiated. For example, you can create a LocalizingElementHost with a ChildChanged event handler that does to the child what you would have done in a base class.

Upvotes: 1

Related Questions