SelectedAlertLevelValidationRule.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. namespace GDNXFD.Alert.Config.Validations
  2. {
  3. using GDNXFD.Alert.Config.ViewModel;
  4. using System;
  5. using System.Windows.Controls;
  6. using System.Windows.Data;
  7. /// <summary>
  8. /// Rule for required fields
  9. /// </summary>
  10. public class SelectedAlertLevelValidationRule : ValidationRule
  11. {
  12. /// <summary>
  13. /// When overridden in a derived class, performs validation checks on a value.
  14. /// </summary>
  15. /// <param name="value">The value from the binding target to check.</param>
  16. /// <param name="cultureInfo">The culture to use in this rule.</param>
  17. /// <returns>
  18. /// A <see cref="T:System.Windows.Controls.ValidationResult"/> object.
  19. /// </returns>
  20. public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
  21. {
  22. if (((RuleFormViewModel)((((BindingExpression)(value)).DataItem))).SelectedAlertLevel == null)
  23. return new ValidationResult(false, "必须选择一个有效值!");
  24. return new ValidationResult(true, null);
  25. }
  26. }
  27. }