How to show date, not date and time in WPF datagrid?

I have a WPF datagrid bound to a class object that looks like this:

<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate }" /> 

The property in the class is pretty simple:

 public DateTime OrderDate { get; set; } 

When I populate this property, I simply send DateTime.Date (only date, not time):

 .Select( r => new Customer { Persona = r.Persona, CustomerName = r.CustomerName, Email = r.Email, Organization = r.Organization, PhoneNumber = r.PhoneNumber, Street = r.Street, Suburb = r.Suburb, Postcode = r.Postcode, OrderDate = r.OrderDate.Date })) 

Unfortunately, this is not reflected in my WPF datagrid document, as it shows the date, but then it also shows the time (everywhere) as 12:00:00AM . How should I approach if only the date-date of WPF shows only the date?

+4
source share
1 answer

try it

 <DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate , StringFormat=d}" /> 

more information about string formats here

+7
source

All Articles