PropertyCondition Constructors

Definition

Initializes a new instance of the PropertyCondition class.

Overloads

PropertyCondition(AutomationProperty, Object)

Initializes a new instance of the PropertyCondition class.

PropertyCondition(AutomationProperty, Object, PropertyConditionFlags)

Initializes a new instance of the PropertyCondition class, with flags.

PropertyCondition(AutomationProperty, Object)

Initializes a new instance of the PropertyCondition class.

C#
public PropertyCondition(System.Windows.Automation.AutomationProperty property, object value);

Parameters

property
AutomationProperty

The property to test.

value
Object

The value to test the property for.

Examples

In the following example, a PropertyCondition specifies that the UI Automation element to be found has a control type of List. The PropertyCondition is then used to obtain the list element from a combo box.

C#
Condition propCondition1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
AutomationElement listElement = elementCombo.FindFirst(TreeScope.Children, propCondition1);

Remarks

The property parameter cannot be BoundingRectangleProperty.

Applies to

.NET Framework 4.8.1 and other versions
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

PropertyCondition(AutomationProperty, Object, PropertyConditionFlags)

Initializes a new instance of the PropertyCondition class, with flags.

C#
public PropertyCondition(System.Windows.Automation.AutomationProperty property, object value, System.Windows.Automation.PropertyConditionFlags flags);

Parameters

property
AutomationProperty

The property to test.

value
Object

The value to test the property for.

flags
PropertyConditionFlags

Flags that affect the comparison.

Examples

The following example uses a PropertyCondition to retrieve the Microsoft UI Automation element representing the main form of an application. The form is located by a case-insensitive search for its string identifier.

C#
/// <summary>
/// Find a UI Automation child element by ID.
/// </summary>
/// <param name="controlName">Name of the control, such as "button1"</param>
/// <param name="parentElement">Parent element, such as an application window, or the 
/// AutomationElement.RootElement when searching for the application window.</param>
/// <returns>The UI Automation element.</returns>
private AutomationElement FindChildElement(String controlName, AutomationElement rootElement)
{
    if ((controlName == "") || (rootElement == null))
    {
        throw new ArgumentException("Argument cannot be null or empty.");
    }
    // Set a property condition that will be used to find the main form of the
    // target application. In the case of a WinForms control, the name of the control
    // is also the AutomationId of the element representing the control.
    Condition propCondition = new PropertyCondition(
        AutomationElement.AutomationIdProperty, controlName, PropertyConditionFlags.IgnoreCase);

    // Find the element.
    return rootElement.FindFirst(TreeScope.Element | TreeScope.Children, propCondition);
}

See also

Applies to

.NET Framework 4.8.1 and other versions
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