TogglePattern.TogglePatternInformation.ToggleState 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索 AutomationElement 的切换状态。
public:
property System::Windows::Automation::ToggleState ToggleState { System::Windows::Automation::ToggleState get(); };
public System.Windows.Automation.ToggleState ToggleState { get; }
member this.ToggleState : System.Windows.Automation.ToggleState
Public ReadOnly Property ToggleState As ToggleState
属性值
ToggleState 的 AutomationElement。 默认值是 Indeterminate。
示例
在下面的示例中,将根元素传递给一个函数,该函数返回自动化元素的集合,这些自动化元素是根的子代并满足一组属性条件。
///--------------------------------------------------------------------
/// <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
注解
AutomationElement必须按以下顺序循环遍历其ToggleState:On、 Off 和 (如果受Indeterminate支持)。