Пример #1
0
        private static void textBox_LostFocus(object sender, RoutedEventArgs e)
        {
            var tb = e.OriginalSource as TextBox;
            ValidationRuleBase rule = GetRule(tb);

            rule.Max    = GetMax(tb);
            rule.Min    = GetMin(tb);
            rule.Number = GetNumber(tb);
            rule.Length = GetLength(tb);
            ValidationResult result = rule.Validate(tb.Text, null);

            if (!result.IsValid)
            {
                MessageBox.Show(result.ErrorContent.ToString(), "提示");
            }
        }
Пример #2
0
 public static void SetRule(DependencyObject d, ValidationRuleBase value)
 {
     d.SetValue(RuleProperty, value);
 }