4

This is the line of code that declares my DatePickerTextBox:

<DatePickerTextBox Text="{Binding dateOfBirth, StringFormat=dd-MM-yyyy}" />

(notice the StringFormat=dd-MM-yyyy)

When the DatePickerTextBox is empty with the placeholder <Enter text here>, and I write in it something like:

01-02-0003

...after clicking outside the DatePickerTextBox, the displayed text automatically changes to:

02-01-0003

(that is: automatically switching month and day)

How can I solve this issue?

Xavier Peña
  • 7,399
  • 9
  • 57
  • 99
  • 1
    As mentioned in [this](http://stackoverflow.com/questions/19279831/why-a-jquery-datepicker-change-days-for-months) article, you might have to add the globalization culture to your app.config. – diiN__________ Mar 11 '16 at 10:00
  • Define culture for your app. for example add this code to your app.config file: ` ` – SᴇM Mar 11 '16 at 10:03
  • or in your `UserControl` or a `Window` add this: `xml:lang="en-US"` – XAMlMAX Mar 11 '16 at 10:26

1 Answers1

6

Its due to culture difference

Define the following xml namespace:

xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"

Specify the CultureInfo relevant to you

<DatePickerTextBox Text="{Binding Path=dateOfBirth, 
                                  StringFormat=dd-MM-yyyy,
                                  ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}" />
Ozzy
  • 304
  • 3
  • 15
Carbine
  • 7,849
  • 4
  • 30
  • 54
  • Than you so much, this seems to do the trick. But before marking it as the correct answer, I still have a little issue I don't seem to be able to solve: although in practice it works, the error list tells me that `The member "CurrentCulture" is not recognized or is not accessible.`. I have tried several things and the error sticks... although the compiler lets me rebuild the solution and run it. I'll try to dig a bit deeper to find a solution. – Xavier Peña Mar 11 '16 at 10:14
  • 1
    Well, as this answer suggests (http://stackoverflow.com/a/35017232/831138) the problem goes away if you target the .NET Framework 4.6 or higher. So I am marking it as the correct answer, but people should be aware that they'll encounter this problem if they use any Framework below v4.6. – Xavier Peña Mar 11 '16 at 10:22
  • Thanks for the info. I wasn't aware. – Carbine Mar 11 '16 at 10:23