WPF DatePicker to show the time as well as the date

user3428422 picture user3428422 · Sep 10, 2014 · Viewed 25.7k times · Source

I have a DatePicker object in a DataGrid that successfully shows the date from the database or a property:

<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
      <DatePicker SelectedDate="{Binding Date, StringFormat=dd/MM/yyyy}"/>
   </DataTemplate>   
</DataGridTemplateColumn.CellTemplate>

Now I want to show the time in front of the date. This is what I tried, but it doesn't work:

<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
      <DatePicker SelectedDate="{Binding Date, StringFormat='dd/MM/yyyy HH:mm:ss'}"/>
   </DataTemplate>   
</DataGridTemplateColumn.CellTemplate>

NOTE: I do not want to do this in the code-behind.

Answer

zaman picture zaman · Sep 10, 2014

Use the extended DateTimePicker