SelectionPattern.SelectionPatternInformation.GetSelection 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取選取容器中所有選取的項目。
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 。
///--------------------------------------------------------------------
/// <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