AutomationElement.GetCurrentPattern(AutomationPattern) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
この AutomationElementで指定されたパターン オブジェクトを取得します。
public:
System::Object ^ GetCurrentPattern(System::Windows::Automation::AutomationPattern ^ pattern);
public object GetCurrentPattern(System.Windows.Automation.AutomationPattern pattern);
member this.GetCurrentPattern : System.Windows.Automation.AutomationPattern -> obj
Public Function GetCurrentPattern (pattern As AutomationPattern) As Object
パラメーター
- pattern
- AutomationPattern
取得するパターンの識別子。
返品
指定したパターンが現在 AutomationElementでサポートされている場合は、パターン オブジェクト。
例外
このパターンは要素でサポートされていません。
AutomationElementの UI が存在しなくなりました。
例
次の例は、このメソッドを使用して SelectionItemPatternを取得する方法を示しています。このメソッドを使用して、リスト ボックス内の項目を選択します。
/// <summary>
/// Sets the focus to a list and selects a string item in that list.
/// </summary>
/// <param name="listElement">The list element.</param>
/// <param name="itemText">The text to select.</param>
/// <remarks>
/// This deselects any currently selected items. To add the item to the current selection
/// in a multiselect list, use AddToSelection instead of Select.
/// </remarks>
public void SelectListItem(AutomationElement listElement, String itemText)
{
if ((listElement == null) || (itemText == ""))
{
throw new ArgumentException("Argument cannot be null or empty.");
}
listElement.SetFocus();
Condition cond = new PropertyCondition(
AutomationElement.NameProperty, itemText, PropertyConditionFlags.IgnoreCase);
AutomationElement elementItem = listElement.FindFirst(TreeScope.Children, cond);
if (elementItem != null)
{
SelectionItemPattern pattern;
try
{
pattern = elementItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message); // Most likely "Pattern not supported."
return;
}
pattern.Select();
}
}
''' <summary>
''' Sets the focus to a list and selects a string item in that list.
''' </summary>
''' <param name="listElement">The list element.</param>
''' <param name="itemText">The text to select.</param>
''' <remarks>
''' This deselects any currently selected items. To add the item to the current selection
''' in a multiselect list, use AddToSelection instead of Select.
''' </remarks>
Public Sub SelectListItem(ByVal listElement As AutomationElement, ByVal itemText As String)
If listElement Is Nothing OrElse itemText = "" Then
Throw New ArgumentException("Argument cannot be null or empty.")
End If
listElement.SetFocus()
Dim cond As New PropertyCondition(AutomationElement.NameProperty, itemText, PropertyConditionFlags.IgnoreCase)
Dim elementItem As AutomationElement = listElement.FindFirst(TreeScope.Children, cond)
If Not (elementItem Is Nothing) Then
Dim pattern As SelectionItemPattern
Try
pattern = DirectCast(elementItem.GetCurrentPattern(SelectionItemPattern.Pattern), _
SelectionItemPattern)
Catch ex As InvalidOperationException
Console.WriteLine(ex.Message) ' Most likely "Pattern not supported."
Return
End Try
pattern.Select()
End If
End Sub
Note
この例のような頻繁に繰り返されるタスクでは、パターンをキャッシュし、 GetCachedPatternを使用する方が効率的です。
注釈
GetCurrentPattern は、呼び出し時の可用性に基づいて、指定されたパターンを取得します。
一部の形式の UI では、このメソッドではプロセス間のパフォーマンス オーバーヘッドが発生します。 アプリケーションは、パターンをキャッシュし、 GetCachedPatternを使用して取得することで、オーバーヘッドを集中させることができます。