I have a datagrid that is bound to an ObservableCollection of custom objects. One of the columns is bound to a DateTime property, and many of the objects have minimum DateTime values.
In my DataGrid, here is my code for the DateTime column
<DataGridTextColumn Binding="{Binding Path=StartTime, StringFormat={}{0:MM/dd/yyyy hh:mm:ss tt}}" Header="Start Time" Foreground="Black" Width="2*"/>
How can I apply a style with a datatemplate or something that can display "-" or "NA" or something if the date is "1/1/1753 12:00:00 AM" or "1/1/0001 12:00:00 AM"?
Use Converter, for example:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is DateTime && (DateTime)value < new DateTime(2, 1, 1))
{
return "NA";
}
else
return value;
}
You should set a minimum/default DateTime
value or a list and compare with DateTime column, return the result what you want.
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