Ejemplo n.º 1
0
        /// <summary>
        /// Validates the visual tree.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="errors">The errors.</param>
        private static void ValidateVisualTree(DependencyObject dependencyObject, ReadOnlyErrorCollection errors)
        {
            var count = VisualTreeHelper.GetChildrenCount(dependencyObject);

            for (var i = 0; i < count; i++)
            {
                var child = VisualTreeHelper.GetChild(dependencyObject, i);
                Validate(child as UIElement, errors);

                ValidateVisualTree(child, errors);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates the tree.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="errors">The errors.</param>
        /// <param name="validationControl">The validation control.</param>
        private static void ValidateTree(DependencyObject dependencyObject, ReadOnlyErrorCollection errors,
		                                 ValidationControl validationControl)
        {
            switch (validationControl.ValidationMethod)
            {
                case TreeType.LogicalTree:
                    ValidateLogicalTree(dependencyObject, errors);
                    break;
                case TreeType.VisualTree:
                    ValidateVisualTree(dependencyObject, errors);
                    break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="errors">The errors.</param>
        private static void Validate(UIElement element, ReadOnlyErrorCollection errors)
        {
            if (element == null)
                return;

            var field = NovaValidation.GetFieldName(element);

            if (string.IsNullOrEmpty(field))
                return;

            if (errors != null)
            {
                var entityID = NovaValidation.GetEntityID(element);

                var validations = errors.GetValidations(field, entityID).ToList();
                if (validations.Count > 0)
                {
                    NovaValidation.SetIsValid(element, false);

                    //Don't get max ranking/put bullets in front of lines when there is only one message to show.
                    if (validations.Count == 1)
                    {
                        var validation = validations.First();

                        NovaValidation.SetValidationTooltip(element, validation.Message);
                        NovaValidation.SetSeverity(element, validation.SeverityBrush);

                        return;
                    }

                    var mostSevereValidationRanking = validations.Max(x => x.Severity);
                    var mostSevereValidation = validations.First(x => x.Severity == mostSevereValidationRanking);

                    NovaValidation.SetSeverity(element, mostSevereValidation.SeverityBrush);

                    //Since we are showing the most severe brush, show the most severe messages first as well.
                    validations = validations.OrderByDescending(x => x.Severity).ToList();

                    if (NovaValidation.GetConcatToolTip(element))
                    {
                        var builder = new StringBuilder();

                        for (int index = 0; index < validations.Count; index++)
                        {
                            var validation = validations[index];
                            builder.Append("• ").Append(validation.Message);

                            if (index + 1 < validations.Count)
                            {
                                builder.AppendLine();
                            }
                        }

                        NovaValidation.SetValidationTooltip(element, builder.ToString());
                    }
                    else
                    {
                        NovaValidation.SetValidationTooltip(element, mostSevereValidation.Message);
                    }

                    return;
                }
            }

            NovaValidation.SetIsValid(element, true);
            NovaValidation.SetValidationTooltip(element, null);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Validates the visual tree.
 /// </summary>
 /// <param name="dependencyObject">The dependency object.</param>
 /// <param name="errors">The errors.</param>
 private static void ValidateLogicalTree(DependencyObject dependencyObject, ReadOnlyErrorCollection errors)
 {
     foreach (var child in LogicalTreeHelper.GetChildren(dependencyObject).OfType<DependencyObject>())
     {
         Validate(child as UIElement, errors);
         ValidateLogicalTree(child, errors);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Sets the errorlist.
 /// </summary>
 /// <param name="dependencyObject">The dependency object.</param>
 /// <param name="value">The value.</param>
 public static void SetErrors(DependencyObject dependencyObject, ReadOnlyErrorCollection value)
 {
     dependencyObject.SetValue(ErrorsProperty, value);
 }