Automation.AddAutomationPropertyChangedEventHandler Metodo

Definizione

Registra un metodo che gestirà eventi di modifica della proprietà.

C#
public static void AddAutomationPropertyChangedEventHandler (System.Windows.Automation.AutomationElement element, System.Windows.Automation.TreeScope scope, System.Windows.Automation.AutomationPropertyChangedEventHandler eventHandler, params System.Windows.Automation.AutomationProperty[] properties);

Parametri

element
AutomationElement

Elemento Automazione interfaccia utente con cui associare il gestore eventi.

scope
TreeScope

Ambito di eventi da gestire; ovvero, se sono sull'elemento stesso o sui predecessori e oggetti figlio.

eventHandler
AutomationPropertyChangedEventHandler

Metodo da chiamare quando si verifica l'evento.

properties
AutomationProperty[]

Proprietà Automazione interfaccia utente di interesse.

Esempio

Il codice di esempio seguente aggiunge un gestore eventi in ascolto di una modifica nello stato abilitato di un elemento specificato.

C#

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);
    }
}

Commenti

L'elemento dell'interfaccia utente specificato dall'elemento Automazione interfaccia utente fornito potrebbe non supportare le proprietà specificate dal properties parametro.

eventHandlerpuò essere un'istanza del metodo o un riferimento al metodo (AddressOf in Visual Basic).

Si applica a

Prodotto Versioni
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Vedi anche