Changing the string format of the WPF DatePicker

benPearce picture benPearce · Sep 29, 2010 · Viewed 87.9k times · Source

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 override this default culture or the display string format?

01-01-2010

Answer

petrycol picture petrycol · Apr 9, 2012

I have solved this problem with a help of this code. Hope it will help you all as well.

<Style TargetType="{x:Type DatePickerTextBox}">
 <Setter Property="Control.Template">
  <Setter.Value>
   <ControlTemplate>
    <TextBox x:Name="PART_TextBox"
     Text="{Binding Path=SelectedDate, StringFormat='dd MMM yyyy', 
     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>