TogglePattern.Pattern 字段

定义

标识 TogglePattern 控件模式。

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

字段值

示例

在以下示例中 TogglePattern ,从 AutomationElement获取控件模式。

///--------------------------------------------------------------------
/// <summary>
/// Obtains a TogglePattern control pattern from an automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A TogglePattern object.
/// </returns>
///--------------------------------------------------------------------
private TogglePattern GetTogglePattern(AutomationElement targetControl)
{
    TogglePattern togglePattern = null;

    try
    {
        togglePattern =
            targetControl.GetCurrentPattern(TogglePattern.Pattern)
            as TogglePattern;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the TogglePattern control pattern
        return null;
    }

    return togglePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a TogglePattern control pattern from an automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A TogglePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTogglePattern( _
ByVal targetControl As AutomationElement) As TogglePattern
    Dim togglePattern As TogglePattern = Nothing

    Try
        togglePattern = DirectCast( _
        targetControl.GetCurrentPattern(togglePattern.Pattern), _
        TogglePattern)
    Catch
        ' object doesn't support the TogglePattern control pattern
        Return Nothing
    End Try

    Return togglePattern

End Function 'GetTogglePattern

注解

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

模式标识符将传递给等 GetCurrentPattern 方法,以便从指定的 AutomationElement检索感兴趣的控件模式。

适用于