TogglePattern.ToggleStateProperty 字段

定义

标识 ToggleState 属性。

public: static initonly System::Windows::Automation::AutomationProperty ^ ToggleStateProperty;
public static readonly System.Windows.Automation.AutomationProperty ToggleStateProperty;
 staticval mutable ToggleStateProperty : System.Windows.Automation.AutomationProperty
Public Shared ReadOnly ToggleStateProperty As AutomationProperty 

字段值

AutomationProperty

示例

在下面的示例中,将根元素传递给一个函数,该函数返回作为根子代的自动化元素集合,并满足一组属性条件。

///--------------------------------------------------------------------
/// <summary>
/// Finds all automation elements that satisfy 
/// the specified condition(s).
/// </summary>
/// <param name="rootElement">
/// The automation element from which to start searching.
/// </param>
/// <returns>
/// A collection of automation elements satisfying 
/// the specified condition(s).
/// </returns>
///--------------------------------------------------------------------
private AutomationElementCollection FindAutomationElement(
    AutomationElement rootElement)
{
    if (rootElement == null)
    {
        throw new ArgumentException("Root element cannot be null.");
    }

    PropertyCondition conditionOn =
        new PropertyCondition(
        TogglePattern.ToggleStateProperty, ToggleState.On);

    PropertyCondition conditionIndeterminate =
        new PropertyCondition(
        TogglePattern.ToggleStateProperty, ToggleState.Indeterminate);

    // Use any combination of the preceding condtions to 
    // find the control(s) of interest
    OrCondition condition = new OrCondition(
        conditionOn,
        conditionIndeterminate);

    return rootElement.FindAll(TreeScope.Descendants, condition);
}
'''--------------------------------------------------------------------
''' <summary>
''' Finds all automation elements that satisfy 
''' the specified condition(s).
''' </summary>
''' <param name="rootElement">
''' The automation element from which to start searching.
''' </param>
''' <returns>
''' A collection of automation elements satisfying 
''' the specified condition(s).
''' </returns>
'''--------------------------------------------------------------------
Private Function FindAutomationElement( _
ByVal rootElement As AutomationElement) As AutomationElementCollection
    If rootElement Is Nothing Then
        Throw New ArgumentException("Root element cannot be null.")
    End If

    Dim conditionOn As New PropertyCondition( _
    TogglePattern.ToggleStateProperty, ToggleState.On)

    Dim conditionIndeterminate As New PropertyCondition( _
    TogglePattern.ToggleStateProperty, ToggleState.Indeterminate)

    ' Use any combination of the preceding condtions to 
    ' find the control(s) of interest
    Dim condition As OrCondition = _
    New OrCondition(conditionOn, conditionIndeterminate)

    Return rootElement.FindAll(TreeScope.Descendants, condition)

End Function 'FindAutomationElement

注解

此标识符由UI 自动化客户端应用程序使用。 UI 自动化提供程序应使用等效字段。TogglePatternIdentifiers

An AutomationElement must cycle through its ToggleState in this order: On, Off and, if supported, Indeterminate.

适用于