protected override void OnHasErrorsChanged() { var hasErrors = this.HasErrors; Scope.SetHasErrors(this.Source, hasErrors); this.UpdateErrors(); var parent = VisualTreeHelper.GetParent(this.Source); if (parent == null) { return; } var node = (Node)parent.GetValue(Scope.ErrorsProperty); if (hasErrors) { if (Scope.GetForInputTypes(parent)?.IsInputType(this.Source) == true) { if (node == null) { Scope.SetErrors(parent, new ScopeNode(parent, this)); } else { node.AddChild(this); } } } else { node?.RemoveChild(this); } }
internal static void Notify(ErrorNode errorNode) { var source = errorNode.Source; if (source == null) { return; } Scope.SetHasErrors(source, errorNode.HasErrors); var parent = VisualTreeHelper.GetParent(source); Node childNode = errorNode; while (parent != null) { if (Scope.GetForInputTypes(parent) == null) { break; } var parentNode = (Node)parent.GetValue(Scope.ErrorsProperty); if (ShouldRemoveChildNode(parentNode, childNode)) { parentNode.RemoveChild(childNode); if (parentNode is ScopeNode && parentNode.Children.Count == 0) { Scope.SetErrors(parent, null); } else { parentNode.RefreshErrors(); } } else if (ShouldAddChildNode(parent, childNode, source)) { if (parentNode == null) { parentNode = new ScopeNode(parent, childNode); Scope.SetErrors(parent, parentNode); } else { parentNode.AddChild(childNode); parentNode.RefreshErrors(); } } Scope.SetHasErrors(parent, parentNode?.HasErrors == true); childNode = parentNode; parent = VisualTreeHelper.GetParent(parent); } }
private static bool IsValidationScopeFor(this DependencyObject parent, DependencyObject source) { if (parent == null || source == null) { return(false); } var inputTypes = Scope.GetForInputTypes(parent); if (inputTypes?.IsInputType(source) == true) { return(true); } if (Scope.GetForInputTypes(parent).Contains(typeof(Scope))) { return(true); } return(false); }