共用方式為


AutomationPropertyChangedEventHandler 代理人

定義

代表使用者介面自動化用戶端應用程式實作的方法,該方法用來處理使用者介面自動化提供者在屬性已變更時所引發之事件。

public delegate void AutomationPropertyChangedEventHandler(System::Object ^ sender, AutomationPropertyChangedEventArgs ^ e);
public delegate void AutomationPropertyChangedEventHandler(object sender, AutomationPropertyChangedEventArgs e);
type AutomationPropertyChangedEventHandler = delegate of obj * AutomationPropertyChangedEventArgs -> unit
Public Delegate Sub AutomationPropertyChangedEventHandler(sender As Object, e As AutomationPropertyChangedEventArgs)

參數

sender
Object

引發事件的物件。

e
AutomationPropertyChangedEventArgs

事件相關資訊。

範例

在下列範例中 IsEnabled ,會處理已訂閱專案的 屬性變更。


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

備註

AutomationElementsender 表示的 可能沒有任何快取的屬性或模式,視應用程式是否在作用中時 CacheRequest 訂閱此事件而定。

根據提供者實作而定,屬性變更的事件不一定表示屬性值不同;它可能只是表示屬性已設定,甚至設定為相同的值。 如果您的應用程式只需要回應實際變更,則您必須負責追蹤屬性的狀態。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱