ControlType.GetRequiredPatternSets Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Retrieves an array of sets of required patterns.

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

public AutomationPattern[][] GetRequiredPatternSets()

Return Value

Type: System.Windows.Automation.AutomationPattern[][]

An array of sets of required patterns.

Each element of the array contains an array of patterns, and each element that has this control type must support at least one of these arrays.

This method is useful for UI Automation clients that need to find all possible patterns, such as testing frameworks for a provider implementation.

The following example calls GetRequiredPatternSets on every kind of ControlType contained as a static field in the ControlType class.

/// <summary>
/// Obtains information about patterns supported by control types.
/// Control types are obtained by reflection.
/// </summary>
private void ListPatterns()
{
    // Any instance of a ControlType will do since we just want to get the type.
    ControlType controlTypeInstance = ControlType.Button;
    Type type = typeof(ControlType);
    System.Reflection.FieldInfo[] fields = type.GetFields();
    foreach (System.Reflection.FieldInfo field in fields)
    {
        if (field.IsStatic)
        {
            ControlType controlType = field.GetValue(controlTypeInstance) as ControlType;
            Console.WriteLine("\n******************** {0} never supports:",
                               controlType.ProgrammaticName);
            AutomationPattern[] neverSupportedPatterns =
                               controlType.GetNeverSupportedPatterns();
            if (neverSupportedPatterns.Length == 0)
            {
                Console.WriteLine("(None)");
            }
            else
            {
                foreach (AutomationPattern pattern in neverSupportedPatterns)
                {
                    Console.WriteLine(pattern.ProgrammaticName);
                }
            }

            Console.WriteLine("\n******************** {0} requires:",
                              controlType.ProgrammaticName);
            AutomationPattern[][] requiredPatternSets =
                              controlType.GetRequiredPatternSets();
            if (requiredPatternSets.Length == 0)
            {
                Console.WriteLine("(None)");
            }
            else
            {
                foreach (AutomationPattern[] patterns in requiredPatternSets)
                {
                    Console.WriteLine("Pattern set:");
                    foreach (AutomationPattern pattern in patterns)
                    {
                        Console.WriteLine(pattern.ProgrammaticName);
                    }
                    Console.WriteLine("--------------------");
                }
            }
        }
    }
}

.NET Framework
Available since 3.0
Return to top
Show: