using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Globalization; using System.Windows.Data; namespace bindings { [ValueConversion(typeof(DateTime), typeof(string))] public class DateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToShortDateString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string strValue = value.ToString(); DateTime resultDateTime; if (DateTime.TryParse(strValue, out resultDateTime)) { return resultDateTime; } return value; } } }