0

I'm working with VS 2015 on a WPF-application, in which the user can change the application language at runtime.

At this point of time we are not working with multiple threads but maybe this will come.

The big question is, which property of the CultureInfo-class is the best to set for all threads of the application?

There are four candidates:

  1. CultureInfo.CurrentCulture

  2. CultureInfo.CurrentUICulture

  3. CultureInfo.DefaultThreadCurrentCulture

  4. CultureInfo.DefaultThreadCurrentUICulture

According to this article it seems to be CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture, but i'm not sure.

Thanks in advance!

Patrick Pirzer
  • 1,649
  • 3
  • 22
  • 49
  • WPF is [tricky](http://stackoverflow.com/q/7454024/1997232) (duplicate?). – Sinatr Feb 09 '17 at 10:52
  • 1
    Big changes in .NET 4.6, the marked answer is no longer correct. Culture now automatically flows, best thing to do is nothing. And of course you can't change the culture of threads that are already running, that hasn't changed. – Hans Passant Feb 09 '17 at 11:12
  • @HansPassant, good to know, thanks. We are still using 4.5 with all those crappy workarounds. – Sinatr Feb 09 '17 at 11:14
  • 4.5 is no longer supported by Microsoft, incrementing to 4.6 is drop-dead easy. – Hans Passant Feb 09 '17 at 11:16

1 Answers1

3

CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture:

Set default thread culture for all thread?

The difference between Culture and UICulture is that the former affects formats (dates, currencies, etc.) while the latter affects resources:

What is the difference between Culture and UICulture?

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thanks a lot mm8. – Patrick Pirzer Feb 09 '17 at 10:53
  • You miss `wpf` tag, controls there are using their own culture. I even had to create [custom binding](http://stackoverflow.com/a/5937477/1997232) to overcome some weird issues (namely changes to settings of current culture in control panel, those aren't taken automagically). Otherwise answer is correct (it will do the thing for e.g. winforms application). – Sinatr Feb 09 '17 at 10:54
  • Controls are created on the UI thread. The CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture properties affect other threads that the application may create. The question is about "multiple threads", isn't it? You don't create controls on background threads. – mm8 Feb 09 '17 at 10:57
  • @Sinatr : In our case we are reading the texts of headers and contents from the database by the help of properties. I know it would work with RESX-files too. – Patrick Pirzer Feb 09 '17 at 11:05
  • @PatrickPirzer, still, if you don't change culture [properly](http://stackoverflow.com/a/7454053/1997232) your `TextBox` suddenly won't correctly recognize user entered numbers (as binding will try to set value of source using default en-US culture). I am simply trying to predict your next very possible issue. – Sinatr Feb 09 '17 at 11:09