Date and month of switching DatePickerTextBox

This is a line of code declaring mine DatePickerTextBox:

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

(pay attention to StringFormat=dd-MM-yyyy)

When DatePickerTextBoxempty with a placeholder <Enter text here>, and I write in it something like:

01-02-0003

... after clicking outside, the DatePickerTextBoxdisplayed text automatically changes to:

02-01-0003

(i.e.: month and day automatically switch )

How can I solve this problem?

+3
source share
1 answer

Due to the difference in culture

Define the following xml namespace:

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

Specify CultureInfo Information that is Right for You

<DatePickerTextBox Text="{Binding Path=dateOfBirth, 
                                  StringFormat=dd-MM-yyyy,
                                  ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}" />
+5
source

Source: https://habr.com/ru/post/1546030/


All Articles