SelectionPattern.SelectionPatternInformation.GetSelection 메서드

정의

선택 컨테이너에서 선택된 모든 항목을 검색합니다.

public:
 cli::array <System::Windows::Automation::AutomationElement ^> ^ GetSelection();
public System.Windows.Automation.AutomationElement[] GetSelection ();
member this.GetSelection : unit -> System.Windows.Automation.AutomationElement[]
Public Function GetSelection () As AutomationElement()

반환

AutomationElement[]

선택된 항목의 컬렉션입니다. 기본값은 빈 배열입니다.

예제

다음 예제에서는 컬렉션에서에서 AutomationElement컨테이너에서 선택한 항목을 나타내는 가져옵니다.

///--------------------------------------------------------------------
/// <summary>
/// Gets the currently selected SelectionItem objects from target.
/// </summary>
/// <param name="ae">The current Selection container object.</param>
///--------------------------------------------------------------------
private AutomationElement[] GetCurrentSelection(
    AutomationElement selectionContainer)
{
    try
    {
        SelectionPattern selectionPattern =
            selectionContainer.GetCurrentPattern(
            SelectionPattern.Pattern) as SelectionPattern;
        return selectionPattern.Current.GetSelection();
    }
    // Container is not enabled
    catch (InvalidOperationException)
    {
        return null;
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' Gets the currently selected SelectionItem objects from target.
''' </summary>
''' <param name="selectionContainer">The current Selection container object.</param>
'''--------------------------------------------------------------------
Private Function GetCurrentSelection( _
ByVal selectionContainer As AutomationElement) As AutomationElement()
    Try
        Dim selectionPattern As SelectionPattern = _
        selectionContainer.GetCurrentPattern(selectionPattern.Pattern)
        Return selectionPattern.Current.GetSelection()
        ' Container is not enabled
    Catch
        Return Nothing
    End Try
End Function 'GetCurrentSelection

적용 대상