AutomationElement.GetCurrentPattern(AutomationPattern) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri a megadott mintaobjektumot ezen AutomationElementa rendszeren.
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
Paraméterek
- pattern
- AutomationPattern
A lekérendő minta azonosítója.
Válaszok
A mintaobjektum, ha a megadott mintát jelenleg támogatja a AutomationElementprogram.
Kivételek
Az elem nem támogatja a mintát.
A felhasználói felület AutomationElement már nem létezik.
Példák
Az alábbi példa bemutatja, hogyan lehet ezzel a módszerrel lekérni egy SelectionItemPatternelemet a listamezőben.
/// <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
Az olyan gyakran ismétlődő feladatok esetében, mint a példában szereplő, hatékonyabb lenne a minta gyorsítótárazása és használata GetCachedPattern.
Megjegyzések
GetCurrentPattern a megadott mintát a hívás időpontjában rendelkezésre állása alapján kapja meg.
A felhasználói felület bizonyos formái esetében ez a módszer folyamatközi teljesítménybeli többletterhelést fog okozni. Az alkalmazások a mintázatok gyorsítótárazásával, majd a használatával történő beolvasásukkal GetCachedPatternkoncentrálhatják a többletterhelést.