Automation.RemoveAutomationPropertyChangedEventHandler Method (AutomationElement, AutomationPropertyChangedEventHandler)


Removes the specified property-changed event handler.

Namespace:   System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public static void RemoveAutomationPropertyChangedEventHandler(
	AutomationElement element,
	AutomationPropertyChangedEventHandler eventHandler


Type: System.Windows.Automation.AutomationElement

The UI Automation element from which to remove the event handler.

Type: System.Windows.Automation.AutomationPropertyChangedEventHandler

A handler method that was passed to AddAutomationPropertyChangedEventHandler for the specified UI Automation element.

The following example code shows a property-changed event handler being added and removed.

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)
        propChangeHandler = new AutomationPropertyChangedEventHandler(OnPropertyChange),


/// <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.
        // TODO: Handle other property-changed events.

public void UnsubscribePropertyChange(AutomationElement element)
    if (propChangeHandler != null)
        Automation.RemoveAutomationPropertyChangedEventHandler(element, propChangeHandler);

.NET Framework
Available since 3.0
Return to top