Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AndCondition Constructor
Collapse the table of content
Expand the table of content

AndCondition Constructor

Creates a PropertyCondition that is true if all the subconditions are true.

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

public AndCondition(
	params Condition[] conditions
)

Parameters

conditions
Type: System.Windows.Automation.Condition[]

Two or more subconditions.

The following example shows how to use AndCondition to find UI Automation elements that match a complex condition.

/// <summary> 
/// Uses AndCondition to retrieve elements that match both of two conditions. 
/// </summary> 
/// <param name="elementMainWindow">An application window element.</param>
public void AndConditionExample(AutomationElement elementMainWindow)
{
    if (elementMainWindow == null)
    {
        throw new ArgumentException();
    }

    AndCondition conditionEnabledButtons = new AndCondition(
        new PropertyCondition(AutomationElement.IsEnabledProperty, true),
        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
    AutomationElementCollection enabledButtons = elementMainWindow.FindAll(
        TreeScope.Subtree, conditionEnabledButtons);
    Console.WriteLine("\nEnabled buttons:");
    foreach (AutomationElement autoElement in enabledButtons)
    {
        Console.WriteLine(autoElement.Current.Name);
    }

    // Example of getting the conditions from the AndCondition.
    Condition[] conditions = conditionEnabledButtons.GetConditions();
    Console.WriteLine("AndCondition has " + conditions.GetLength(0) + " subconditions.");

}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft