private bool IsValid(System.Windows.DependencyObject obj)
{
// The dependency object is valid if it has no errors and all
// of its children (that are dependency objects) are error-free.
return !Validation.GetHasError(obj) &&
System.Windows.LogicalTreeHelper.GetChildren(obj)
.OfType<System.Windows.DependencyObject>()
.All(IsValid);
}