SelectionPattern.SelectionPatternInformation.GetSelection Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves all items in the selection container that are selected.
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()
Returns
The collection of selected items. The default is an empty array.
Examples
In the following example, a collection of AutomationElements representing the selected items in a selection container is obtained.
///--------------------------------------------------------------------
/// <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
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET