I have a WPF datagrid with a binding to a class object that looks like the following:
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate }" />
The property in the class is quite simple, as follows:
public DateTime OrderDate { get; set; }
When I'm populating this property I'm just sending DateTime.Date
(date only, 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 doesn't reflect in my WPF datagrid as that's showing the date, but then it's also showing the time (everywhere) as 12:00:00AM
. How should I approach just having my WPF datagrid show the date only?
Try this
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate , StringFormat=d}" />
more info on string formattings here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With