Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you could use a IValueConverter (which takes in a culture parameter) and format the value as you wish, something I like is this nullable converter by Matt Hamilton</p> <pre><code>class NullableDateTimeConverter : ValidationRule, IValueConverter { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (value == null || value.ToString().Trim().Length == 0) return null; return new ValidationResult( ConvertBack(value, typeof(DateTime?), null, cultureInfo) != DependencyProperty.UnsetValue, "Please enter a valid date, or leave this value blank"); } #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return ""; DateTime? dt = value as DateTime?; if (dt.HasValue) { return parameter == null ? dt.Value.ToString() : dt.Value.ToString(parameter.ToString()); } return ""; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || value.ToString().Trim().Length == 0) return null; string s = value.ToString(); if (s.CompareTo("today") == 0) return DateTime.Today; if (s.CompareTo("now") == 0) return DateTime.Now; if (s.CompareTo("yesterday") == 0) return DateTime.Today.AddDays(-1); if (s.CompareTo("tomorrow") == 0) return DateTime.Today.AddDays(1); DateTime dt; if (DateTime.TryParse(value.ToString(), out dt)) return dt; return DependencyProperty.UnsetValue; } #endregion </code></pre> <p>} </p> <p>heres the <a href="http://www.madprops.org/blog/A-Nullable-DateTime-IValueConverter-and-ValidationRule/" rel="nofollow noreferrer">original</a> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload