AutomationElement.TryGetCurrentPattern(AutomationPattern, Object) Method

Definition

Retrieves an object that implements a control pattern.

C#
public bool TryGetCurrentPattern(System.Windows.Automation.AutomationPattern pattern, out object patternObject);

Parameters

pattern
AutomationPattern

The identifier of the control pattern to retrieve.

patternObject
Object

On return, the control pattern if it is supported; otherwise null.

Returns

true if the pattern is supported; otherwise false.

Examples

The following example shows how to use this method to retrieve a control pattern.

C#
// element is an AutomationElement.
object objPattern;
SelectionPattern selPattern;
if (true == element.TryGetCurrentPattern(SelectionPattern.Pattern, out objPattern))
{
    selPattern = objPattern as SelectionPattern;
}

Remarks

For some forms of user interface (UI), this method will incur cross-process performance overhead. Applications can concentrate overhead by caching patterns and then retrieving them by using GetCachedPattern.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also