GetPattern Method

FrameworkElementAutomationPeer.GetPattern Method

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns an object that supports the requested pattern, based on the patterns supported by this FrameworkElementAutomationPeer.

Namespace:  System.Windows.Automation.Peers
Assembly:  System.Windows (in System.Windows.dll)

public override Object GetPattern(
	PatternInterface patternInterface
)

Parameters

patternInterface
Type: System.Windows.Automation.Peers.PatternInterface
One of the enumeration values.

Return Value

Type: System.Object
See Remarks.

The return value for this method in the FrameworkElementAutomationPeer implementation returns null in all cases. Override this method to report a specific pattern.

The following is a basic example implementation.

public override object GetPattern(PatternInterface patternInterface)
{
    if (patternInterface == PatternInterface.SelectionItem)
    {
        return this;
    }
    return null;
}

This example returns a result whenever the requester code has specified PatternInterface.SelectionItem as a requested pattern. Note the return of "this". The caller is then expected to cast "this" to the pattern interface that corresponds to the pattern they requested. In this case the calling code should cast the return value to ISelectionItemProvider, which then enables the calling code to invoke supported pattern members such as AddToSelection().

Note that many Windows Phone peer implementations implement their supported pattern members through explicit interface implementations. This is one reason why callers should always cast the GetPattern return specifically to the interface of the desired pattern; the pattern members of a peer would otherwise not be accessible as direct members of the class.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft