Changing the string format of the WPF DatePicker

前端 未结 9 1775
广开言路
广开言路 2020-11-27 14:56

I need to change the string format of the DatePickerTextBox in the WPF Toolkit DatePicker, to use hyphens instead of slashes for the seperators.

Is there a way to ov

9条回答
  •  失恋的感觉
    2020-11-27 15:37

    As Ben Pearce answered we can use the CultureInfo Class to take care of the Custom Format, I really think is the only logical way. And if you have different dateTimePickers which have different Format, you can use:

    CultureInfo ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
    ci.DateTimeFormat.LongDatePattern = "MMM.yyyy"; //This can be used for one type of DatePicker
    ci.DateTimeFormat.ShortDatePattern = "dd.MMM.yyyy"; //for the second type
    Thread.CurrentThread.CurrentCulture = ci;
    

    And then you can just change the DateFormat in the .xaml document.

      
    

提交回复
热议问题