WPF RadDatePicker Enter Date Order

502 Views Asked by At

I have form with more than one RadDatePicker, Every thing work fine but when I want to enter date I want the end user enter date in format dd/mm/yyyy BUT the tool accept only date in format mm/dd/yyyy order!!

Example: 13/12/2016 If the user enter 13 then press spacebar then type 12 then press spacebar 2016 then press enter It gives Error

enter image description here

How can I change the format for entering date?

Thanks in advance.

2

There are 2 best solutions below

0
On

Finally, I solved the issue by changing the culture from "en-US" to "ar-LY"

<telerik:RadDatePicker Culture="ar-LY"/>

Also, You can check .NET Framework Cultures with Date and Time String Formats

Hope this help.

6
On

Try set ShortDatePattern in DateTimeFormatInfo:

CultureInfo cultureInfo = new CultureInfo("en-US");  
DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();  
dateInfo.ShortDatePattern = "dd/MM/yyyy";  
cultureInfo.DateTimeFormat = dateInfo;  
radDatePicker1.Culture = cultureInfo; 

You should also implement custom parsing: http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/how-to/implement-custom-parsing

Example:

private void radDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
    DateTime date;
    string input = args.TextToParse.ToLower();
    CultureInfo provider = CultureInfo.InvariantCulture;
    string format = "dd/MM/yyyy";
    if (DateTime.TryParseExact(input, format, provider, DateTimeStyles.None, out date))
    {
        args.Result = date;
    }
    else
    {
        args.IsParsingSuccessful = false;
    }
}