AutomationProperty 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
标识 AutomationElement 的属性。
public ref class AutomationProperty : System::Windows::Automation::AutomationIdentifier
public class AutomationProperty : System.Windows.Automation.AutomationIdentifier
type AutomationProperty = class
inherit AutomationIdentifier
Public Class AutomationProperty
Inherits AutomationIdentifier
- 继承
示例
以下示例添加属性更改的事件处理程序,处理程序检查 Property 事件参数的成员以确定已更改的属性。
AutomationPropertyChangedEventHandler propChangeHandler;
/// <summary>
/// Adds a handler for property-changed event; in particular, a change in the enabled state.
/// </summary>
/// <param name="element">The UI Automation element whose state is being monitored.</param>
public void SubscribePropertyChange(AutomationElement element)
{
Automation.AddAutomationPropertyChangedEventHandler(element,
TreeScope.Element,
propChangeHandler = new AutomationPropertyChangedEventHandler(OnPropertyChange),
AutomationElement.IsEnabledProperty);
}
/// <summary>
/// Handler for property changes.
/// </summary>
/// <param name="src">The source whose properties changed.</param>
/// <param name="e">Event arguments.</param>
private void OnPropertyChange(object src, AutomationPropertyChangedEventArgs e)
{
AutomationElement sourceElement = src as AutomationElement;
if (e.Property == AutomationElement.IsEnabledProperty)
{
bool enabled = (bool)e.NewValue;
// TODO: Do something with the new value.
// The element that raised the event can be identified by its runtime ID property.
}
else
{
// TODO: Handle other property-changed events.
}
}
public void UnsubscribePropertyChange(AutomationElement element)
{
if (propChangeHandler != null)
{
Automation.RemoveAutomationPropertyChangedEventHandler(element, propChangeHandler);
}
}
Dim propChangeHandler As AutomationPropertyChangedEventHandler
''' <summary>
''' Adds a handler for property-changed event; in particular, a change in the enabled state.
''' </summary>
''' <param name="element">The UI Automation element whose state is being monitored.</param>
Public Sub SubscribePropertyChange(ByVal element As AutomationElement)
propChangeHandler = _
New AutomationPropertyChangedEventHandler(AddressOf OnPropertyChange)
Automation.AddAutomationPropertyChangedEventHandler(element, TreeScope.Element, _
propChangeHandler, AutomationElement.IsEnabledProperty)
End Sub
''' <summary>
''' Handler for property changes.
''' </summary>
''' <param name="src">The source whose properties changed.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnPropertyChange(ByVal src As Object, ByVal e As AutomationPropertyChangedEventArgs)
Dim sourceElement As AutomationElement = DirectCast(src, AutomationElement)
If e.Property Is AutomationElement.IsEnabledProperty Then
Dim enabled As Boolean = CBool(e.NewValue)
' TODO: Do something with the new value.
' The element that raised the event can be identified by its runtime ID property.
Else
End If
' TODO: Handle other property-changed events.
End Sub
Public Sub UnsubscribePropertyChange(ByVal element As AutomationElement)
If (propChangeHandler IsNot Nothing) Then
Automation.RemoveAutomationPropertyChangedEventHandler(element, propChangeHandler)
End If
End Sub
注解
此类标识属性,而不是属性的值。 此类型的静态对象作为字段 AutomationElement 和控件模式类找到。
属性
Id |
获取基础数值标识符。 (继承自 AutomationIdentifier) |
ProgrammaticName |
获取注册的编程名称。 (继承自 AutomationIdentifier) |
方法
CompareTo(Object) |
将此 AutomationIdentifier 与其他 AutomationIdentifier 相比较。 (继承自 AutomationIdentifier) |
Equals(Object) |
返回一个值,该值指示提供的 AutomationIdentifier 是否等效于此 AutomationIdentifier。 (继承自 AutomationIdentifier) |
GetHashCode() |
返回此UI 自动化标识符的哈希代码。 (继承自 AutomationIdentifier) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
LookupById(Int32) |
检索一个封装了指定数值标识符的 AutomationProperty。 |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |