■ LogicalTreeHelper 클래스 : 무효한 IInputElement 객체 찾기

----------------------------------------------------------------------------------------------------

using System.Windows;

 

#region 무효한 IInputElement 객체 찾기 - FindInvalidInputElement(parentDependencyObject)

 

/// <summary>

/// 무효한 IInputElement 객체 찾기

/// </summary>

/// <param name="parentDependencyObject">부모 DependencyObject 객체</param>

/// <returns>무효한 입력 엘리먼트 객체</returns>

/// <remarks>ValidationRule 객체를 설정한 IInputElement 객체 중에서 에러를 갖는 객체를 찾는다.</remarks>

private IInputElement FindInvalidInputElement(DependencyObject parentDependencyObject)

{

    if(parentDependencyObject == null)

    {

        return null;

    }

 

    if(parentDependencyObject is IInputElement)

    {

        if(Validation.GetHasError(parentDependencyObject))

        {

            return parentDependencyObject as IInputElement;

        }

    }

 

    foreach(object childObject in LogicalTreeHelper.GetChildren(parentDependencyObject))

    {

        if(childObject is DependencyObject)

        {

            IInputElement invalidInputElement = FindInvalidInputElement(childObject as DependencyObject);

 

            if(invalidInputElement != null)

            {

                return invalidInputElement;

            }

        }

    }

            

    return null;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요