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()
返回
已选定项的集合。 默认为空数组。
示例
在以下示例中,获取表示所选容器中选定项的 AutomationElements 集合。
///--------------------------------------------------------------------
/// <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