Ejemplo n.º 1
0
        static void RuleChanged(ValidationStatusControl status, BrokenRuleEventArgs args, bool isValid)
        {
            if (!isValid)
            {
                status.fieldErrors.Add(args.BrokenRule);
            }
            else
            {
                status.fieldErrors.Remove(args.BrokenRule);
            }

            var strs = from brokenRule in status.fieldErrors
                       select brokenRule.Message;

            status.ErrorMessage = string.Join(Environment.NewLine, strs.ToArray());
        }
Ejemplo n.º 2
0
        private static void EntityChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ValidationStatusControl status = d as ValidationStatusControl;

            Debug.Assert(status != null);

            EventHandler <BrokenRuleEventArgs> ruleRep   = delegate(object sender, BrokenRuleEventArgs args) { RuleChanged(status, args, true); };
            EventHandler <BrokenRuleEventArgs> ruleBreak = delegate(object sender, BrokenRuleEventArgs args) { RuleChanged(status, args, false); };



            if (e.OldValue != null)
            {
                var c = ((EntityBase)e.OldValue).Extensions.BrokenRules;

                c.RuleRepaired -= ruleRep;
                c.RuleBroken   -= ruleBreak;
                foreach (var brokenRule in c)
                {
                    RuleChanged(status, new BrokenRuleEventArgs(brokenRule), true);
                }
            }

            if (e.NewValue == null)
            {
                return;
            }

            {
                var c = ((EntityBase)e.NewValue).Extensions.BrokenRules;

                c.RuleRepaired += ruleRep;
                c.RuleBroken   += ruleBreak;

                foreach (var brokenRule in c)
                {
                    RuleChanged(status, new BrokenRuleEventArgs(brokenRule), false);
                }
            }
        }