Setting the Culture of only a single view, not the entire program

314 views Asked by At

I have been trying for quite a while to find a way to set the culture of only a single view and/or its viewmodel.

to date i have used:

    System.Globalization.CultureInfo NewCulture = new System.Globalization.CultureInfo("en-US");
    Thread.CurrentThread.CurrentCulture = NewCulture;

which has given me Reasonably good success.

BUT, it sets the culture of the entire thread.(I MAY NOT have this).

it must not touch the culture of the thread.

QUESTION

Do you know of any other way for me to set the culture of a view/viewmodel to en-US?

It must not set the culture of the thread, and it must not set the culture of any other views or their viewmodels, only the view and viewmodels that i have chosen.

1

There are 1 answers

4
mm8 On

It depends on what you want to accomplish by changing the culture. The FrameworkElement class has a Language property that you can set to change the language of an element. It can for example be used to change the language/culture of a Calendar and the formatting of a number:

<Calendar Language="en-US" />

<TextBlock Text="{Binding DecimalValue}" Language="sv-SE" />

You could specify the language in a property of your view model and bind to this:

<TextBlock Text="{Binding Val}" Language="{Binding Language}" />