//=============================================================================== // Goal Book. // Copyright © 2009 Mark Brownsword. //=============================================================================== #region Using Statements using System; using System.Windows.Data; using GoalBook.Infrastructure.Constants; #endregion namespace GoalBook.Infrastructure.Converters { /// <summary> /// Value Converter for object model item foreign DateTime fields. /// </summary> public class DateTimeConverter : IValueConverter { #region IValueConverter Members /// <summary> /// Convert DateTime. /// </summary> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return DateComparisonConstants.NO_DATE_SPECIFIED; } DateTime result; if (DateTime.TryParse(value.ToString(), out result)) { return result.ToString(parameter.ToString()); } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value.ToString() == DateComparisonConstants.NO_DATE_SPECIFIED) { return null; } return System.Convert.ToDateTime(value); } #endregion } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)