다음을 통해 공유


ExpandCollapsePattern.Expand 메서드

정의

AutomationElement의 모든 자식 노드, 컨트롤 또는 내용을 표시합니다.

public:
 void Expand();
public void Expand ();
member this.Expand : unit -> unit
Public Sub Expand ()

예외

예제

다음 예제에서는 AutomationElement 현재를 기준으로 메뉴 항목을 펼치거나 하려고 하는 함수에 전달 되는 메뉴 항목을 나타내는 ExpandCollapseState합니다.

///--------------------------------------------------------------------
/// <summary>
/// Obtains an ExpandCollapsePattern control pattern from an 
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A ExpandCollapsePattern object.
/// </returns>
///--------------------------------------------------------------------
private ExpandCollapsePattern GetExpandCollapsePattern(
    AutomationElement targetControl)
{
    ExpandCollapsePattern expandCollapsePattern = null;

    try
    {
        expandCollapsePattern =
            targetControl.GetCurrentPattern(
            ExpandCollapsePattern.Pattern)
            as ExpandCollapsePattern;
    }
    // Object doesn't support the ExpandCollapsePattern control pattern.
    catch (InvalidOperationException)
    {
        return null;
    }

    return expandCollapsePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an ExpandCollapsePattern control pattern from an 
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A ExpandCollapsePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetExpandCollapsePattern( _
ByVal targetControl As AutomationElement) As ExpandCollapsePattern
    Dim expandCollapsePattern As ExpandCollapsePattern = Nothing

    Try
        expandCollapsePattern = DirectCast( _
        targetControl.GetCurrentPattern(expandCollapsePattern.Pattern), _
        ExpandCollapsePattern)
    Catch exc As InvalidOperationException
        ' Object doesn't support the ExpandCollapsePattern control pattern.
        Return Nothing
    End Try

    Return expandCollapsePattern

End Function 'GetExpandCollapsePattern
///--------------------------------------------------------------------
/// <summary>
/// Programmatically expand or collapse a menu item.
/// </summary>
/// <param name="menuItem">
/// The target menu item.
/// </param>
///--------------------------------------------------------------------
private void ExpandCollapseMenuItem(
    AutomationElement menuItem)
{
    if (menuItem == null)
    {
        throw new ArgumentNullException(
            "AutomationElement argument cannot be null.");
    }

    ExpandCollapsePattern expandCollapsePattern =
        GetExpandCollapsePattern(menuItem);

    if (expandCollapsePattern == null)
    {
        return;
    }

    if (expandCollapsePattern.Current.ExpandCollapseState ==
        ExpandCollapseState.LeafNode)
    {
        return;
    }

    try
    {
        if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded)
        {
            // Collapse the menu item.
            expandCollapsePattern.Collapse();
        }
        else if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed ||
            expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.PartiallyExpanded)
        {
            // Expand the menu item.
            expandCollapsePattern.Expand();
        }
    }
    // Control is not enabled
    catch (ElementNotEnabledException)
    {
        // TO DO: error handling.
    }
    // Control is unable to perform operation.
    catch (InvalidOperationException)
    {
        // TO DO: error handling.
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Programmatically expand or collapse a menu item.
''' </summary>
''' <param name="menuItem">
''' The target menu item.
''' </param>
'''--------------------------------------------------------------------
Private Sub ExpandCollapseMenuItem(ByVal menuItem As AutomationElement)
    If menuItem Is Nothing Then
        Throw New ArgumentNullException( _
        "AutomationElement argument cannot be null.")
    End If

    Dim expandCollapsePattern As ExpandCollapsePattern = _
    GetExpandCollapsePattern(menuItem)

    If expandCollapsePattern Is Nothing Then
        Return
    End If

    If expandCollapsePattern.Current.ExpandCollapseState = _
    ExpandCollapseState.LeafNode Then
        Return
    End If

    Try
        If expandCollapsePattern.Current.ExpandCollapseState = _
        ExpandCollapseState.Expanded Then
            ' Collapse the menu item.
            expandCollapsePattern.Collapse()

        ElseIf expandCollapsePattern.Current.ExpandCollapseState = _
        ExpandCollapseState.Collapsed OrElse _
        expandCollapsePattern.Current.ExpandCollapseState = _
        ExpandCollapseState.PartiallyExpanded Then
            ' Expand the menu item.
            expandCollapsePattern.Expand()
        End If
    Catch exc As ElementNotEnabledException
        ' Control is not enabled
        ' TO DO: error handling.
    Catch exc As InvalidOperationException
        ' Control is unable to perform operation 
        ' TO DO: error handling.
    End Try

End Sub

설명

메서드입니다. 차단 후 반환 하는 AutomationElement 확장 되었습니다.

가지 경우 사례를 AutomationElement 리프 노드는 될 때까지 자식에 있는지 여부를 모를 수 있습니다 하는 것으로 표시 되는 합니다 Collapse 또는 Expand 메서드가 호출 됩니다. 이 동작은 트리 뷰 컨트롤을 수행 하는 지연 된 해당 자식 항목의 로드를 사용 하 여 가능 합니다. 예를 들어 Microsoft Windows Explorer는 현재 자식 항목이 없더라도 노드에 대한 확장 아이콘을 표시할 수 있습니다. 아이콘을 클릭하면 컨트롤이 자식 항목을 폴링하고 없음을 찾은 다음 확장 아이콘을 제거합니다. 이러한 경우 클라이언트 수신 대기할 속성 변경 이벤트에 대 한 합니다 ExpandCollapseState 이벤트 처리기를 등록 하 여 속성을 AddAutomationPropertyChangedEventHandler 메서드.

적용 대상

추가 정보