FrameworkElementAutomationPeer.GetPattern Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Overrides Function GetPattern ( _
    patternInterface As PatternInterface _
) As Object
public override Object GetPattern(
    PatternInterface patternInterface
)

Parameters

Return Value

Type: System.Object
See Remarks.

Remarks

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

Examples

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 Silverlight 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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.