RequiredValidationRule.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. namespace GDNXFD.Alert.Config.Validations
  2. {
  3. using System;
  4. using System.Windows.Controls;
  5. /// <summary>
  6. /// Rule for required fields
  7. /// </summary>
  8. public class RequiredValidationRule : ValidationRule
  9. {
  10. /// <summary>
  11. /// When overridden in a derived class, performs validation checks on a value.
  12. /// </summary>
  13. /// <param name="value">The value from the binding target to check.</param>
  14. /// <param name="cultureInfo">The culture to use in this rule.</param>
  15. /// <returns>
  16. /// A <see cref="T:System.Windows.Controls.ValidationResult"/> object.
  17. /// </returns>
  18. public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
  19. {
  20. if (value == null || String.IsNullOrWhiteSpace(value.ToString()))
  21. {
  22. return new ValidationResult(false, "不能为空!");
  23. }
  24. return new ValidationResult(true, null);
  25. }
  26. }
  27. }