コード例 #1
0
ファイル: DummyRule.cs プロジェクト: SmaSTra/SmaSTra
        /// <summary>
        /// Marks the specified FrameworkElement as invalid using the DummyRule
        /// in combination with the DummyErrorProperty to fabricate a ValidationError.
        /// </summary>
        /// <param name="frameworkElement">The framework element that is supposed to have a validation error.</param>
        /// <param name="errorContent">Content of the error that is added to the framework element.</param>
        /// <param name="newMark">if set to <c>true</c> a new error is simply added else
        /// any existing error is cleared before adding.</param>
        /// <exception cref="ArgumentNullException" />
        public static void MarkInvalid(FrameworkElement frameworkElement, object errorContent, bool newMark)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException("Argument 'frameworkElement' must not be null.");
            }

            if (newMark)
            {
                DummyRule.ClearInvalid(frameworkElement);
            }

            if (!BindingOperations.IsDataBound(frameworkElement, DummyRule.DummyErrorProperty))
            {
                DummyRule rule    = new DummyRule(false, errorContent);
                Binding   binding = new Binding("ErrorContent")
                {
                    Source = rule
                };
                binding.ValidationRules.Add(rule);
                BindingOperations.SetBinding(frameworkElement, DummyRule.DummyErrorProperty, binding);

                BindingExpression bindex = BindingOperations.GetBindingExpression(frameworkElement, DummyRule.DummyErrorProperty);

                Validation.MarkInvalid(bindex, new ValidationError(rule, binding, errorContent, null));

                bindex.UpdateSource();
            }
        }
コード例 #2
0
ファイル: DummyRule.cs プロジェクト: SmaSTra/SmaSTra
        /// <summary>
        /// Marks the specified FrameworkElement as invalid using the DummyRule
        /// in combination with the DummyErrorProperty to fabricate a ValidationError.
        /// </summary>
        /// <param name="frameworkElement">The framework element that is supposed to have a validation error.</param>
        /// <param name="errorContent">Content of the error that is added to the framework element.</param>
        /// <exception cref="ArgumentNullException" />
        public static void MarkInvalid(FrameworkElement frameworkElement, object errorContent)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException("Argument 'frameworkElement' must not be null.");
            }

            DummyRule.MarkInvalid(frameworkElement, errorContent, false);
        }