AutomationElement.TryGetCurrentPattern(AutomationPattern, Object) 方法

定義

擷取實作控制項模式的物件。Retrieves an object that implements a control pattern.

public:
 bool TryGetCurrentPattern(System::Windows::Automation::AutomationPattern ^ pattern, [Runtime::InteropServices::Out] System::Object ^ % patternObject);
public bool TryGetCurrentPattern (System.Windows.Automation.AutomationPattern pattern, out object patternObject);
member this.TryGetCurrentPattern : System.Windows.Automation.AutomationPattern * obj -> bool
Public Function TryGetCurrentPattern (pattern As AutomationPattern, ByRef patternObject As Object) As Boolean

參數

pattern
AutomationPattern

要擷取之控制項模式的識別項。The identifier of the control pattern to retrieve.

patternObject
Object

傳回時,如果支援則為控制項模式;否則為 nullOn return, the control pattern if it is supported; otherwise null.

傳回

Boolean

true 表示支援該模式;否則為 falsetrue if the pattern is supported; otherwise false.

範例

下列範例顯示如何使用這個方法來抓取控制項模式。The following example shows how to use this method to retrieve a control pattern.

// element is an AutomationElement.
object objPattern;
SelectionPattern selPattern;
if (true == element.TryGetCurrentPattern(SelectionPattern.Pattern, out objPattern))
{
    selPattern = objPattern as SelectionPattern;
}
' element is an AutomationElement.
Dim objPattern As Object = Nothing
Dim selPattern As SelectionPattern
If True = element.TryGetCurrentPattern(SelectionPattern.Pattern, objPattern) Then
    selPattern = DirectCast(objPattern, SelectionPattern)
End If

備註

針對某些形式的使用者介面 (UI) ,這個方法會產生跨進程的效能額外負荷。For some forms of user interface (UI), this method will incur cross-process performance overhead. 應用程式可以藉由快取模式,然後使用來加以抓取,藉以專注額外負荷 GetCachedPatternApplications can concentrate overhead by caching patterns and then retrieving them by using GetCachedPattern.

適用於

另請參閱