0

I have a label with the content bound to a DateTime object. I want the format of the DateTime to be dynamic, i.e. if the user changes the culture of the program, the format of the DateTime should change accordingly.

I have a SetCulture method which calls the following:

Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(culture);

I have tried this for the label:

Content="{Binding Model.DateTimeNow, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"

However the format does not change even when I set a different culture through the methods above.

How can I achieve a dynamic DateTime format?

gartenriese
  • 4,131
  • 6
  • 36
  • 60
  • Is `Model.DateTimeNow` a string or a `DateTime` value? – Jai Jun 22 '16 at 09:56
  • @Jai: An instance of `DateTime`. Should it be a string instead? – gartenriese Jun 22 '16 at 09:57
  • Try doing [this](http://stackoverflow.com/questions/520115/stringformat-localization-issues-in-wpf/520334#520334) – Jai Jun 22 '16 at 10:04
  • @Clemens Yup, actually it would work with an actual converter attached to it. – Jai Jun 22 '16 at 10:18
  • The most simple solution seems to be to remove the ConverterCulture from the binding and just set the Window's Language, as shown here: http://stackoverflow.com/a/5169037/1136211 – Clemens Jun 22 '16 at 10:34
  • @Clemens: This is not dynamic though, I have to set the Language each time I change the culture. – gartenriese Jun 22 '16 at 11:05
  • @Jai: That won't change it dynamically, and furthermore, I can't call it more than once. – gartenriese Jun 22 '16 at 11:07
  • @gartenriese It works well for me. Of course the binding source property has to be updated to trigger the binding. – Clemens Jun 22 '16 at 11:17
  • @Clemens: It still doesn't work, even when I'm updating my binding source property after changing the culture. – gartenriese Jun 22 '16 at 11:55

0 Answers0