Files
BeWoPlaner/BeWo/Converter/DateConverter.cs
2016-06-27 01:45:38 +02:00

36 lines
989 B
C#

using System;
using System.Globalization;
using System.Windows.Data;
namespace BeWo.Converter
{
[ValueConversion(typeof(DateTime?), typeof(string))]
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string s = string.Empty;
DateTime? lDateTime = (DateTime?)value;
if (lDateTime.HasValue)
{
s = lDateTime.Value.ToShortDateString();
}
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime temp;
DateTime.TryParse((string)value, out temp);
if (temp != DateTime.MinValue)
{
return temp;
}
else
{
return null;
}
}
}
}