2

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.

Bernard Walters
  • 391
  • 1
  • 4
  • 16

1 Answers1

1

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}" />
mm8
  • 163,881
  • 10
  • 57
  • 88
  • I am voting this up, because i know it is a solution, not the solution to my very specific problem, but it is a working solution . – Bernard Walters Dec 14 '16 at 15:23
  • What is your specific problem exactly? – mm8 Dec 14 '16 at 15:36
  • i have a sql server that is en-US and my local culture is en-ZA, the winforms reportviewer takes my local culture and is readonly when you try to set its culture...you can set the reportviwer language, BUT it makes no difference it stays en-ZA.... the only thing that has worked so far was Thread.CurrentThread.CurrentCulture = NewCulture; – Bernard Walters Dec 14 '16 at 15:43
  • That's probably the only solution I am afraid. The WinForms DateTimePicker control does for example always use the OS language settings regardless of the thread's current culture and there is no other way to change the language for the ReportViewer than setting the Thread.CurrentThread.CurrentCulture property. – mm8 Dec 14 '16 at 15:54