first edit
This commit is contained in:
25
XLIMS.MVVM/Converters/DateConverter.cs
Normal file
25
XLIMS.MVVM/Converters/DateConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user