26 lines
820 B
C#
26 lines
820 B
C#
using System;
|
|
using System.Windows.Data;
|
|
using System.Globalization;
|
|
|
|
namespace XLIMS.MVVM.Converters
|
|
{
|
|
[ValueConversion(typeof(DateTime), typeof(string))]
|
|
public class DateConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (!(value is DateTime)) return string.Empty;
|
|
DateTime test = (DateTime)value;
|
|
string date = test.ToString();
|
|
return (date);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var strValue = value.ToString();
|
|
DateTime resultDateTime;
|
|
return DateTime.TryParse(strValue, out resultDateTime) ? resultDateTime : value;
|
|
}
|
|
}
|
|
}
|