Automation.AddStructureChangedEventHandler Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Registra il metodo che gestirà eventi di modifica della struttura.
public:
static void AddStructureChangedEventHandler(System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::TreeScope scope, System::Windows::Automation::StructureChangedEventHandler ^ eventHandler);
public static void AddStructureChangedEventHandler (System.Windows.Automation.AutomationElement element, System.Windows.Automation.TreeScope scope, System.Windows.Automation.StructureChangedEventHandler eventHandler);
static member AddStructureChangedEventHandler : System.Windows.Automation.AutomationElement * System.Windows.Automation.TreeScope * System.Windows.Automation.StructureChangedEventHandler -> unit
Public Shared Sub AddStructureChangedEventHandler (element As AutomationElement, scope As TreeScope, eventHandler As StructureChangedEventHandler)
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 discendenti.
- eventHandler
- StructureChangedEventHandler
Metodo da chiamare quando si verifica l'evento di modifica della struttura.
Esempio
Nell'esempio seguente viene illustrato un delegato del gestore eventi modificato dalla struttura che verrà chiamato ogni volta che viene chiamato il sottoalbero delle modifiche specificate AutomationElement .
/// <summary>
/// Handles structure-changed events. If a new app window has been added, this method ensures
/// it's in the list of runtime IDs and subscribed to window-close events.
/// </summary>
/// <param name="sender">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>
/// An exception can be thrown by the UI Automation core if the element disappears
/// before it can be processed -- for example, if a menu item is only briefly visible.
/// This exception cannot be caught here because it crosses native/managed boundaries.
/// In the debugger, you can ignore it and continue execution. The exception does not cause
/// a break when the executable is being run.
/// </remarks>
private void OnStructureChanged(object sender, StructureChangedEventArgs e)
{
AutomationElement element = sender as AutomationElement;
if (e.StructureChangeType == StructureChangeType.ChildAdded)
{
Object windowPattern;
if (false == element.TryGetCurrentPattern(WindowPattern.Pattern, out windowPattern))
{
return;
}
int[] rid = e.GetRuntimeId();
if (RuntimeIdListed(rid, savedRuntimeIds) < 0)
{
AddToWindowHandler(element);
savedRuntimeIds.Add(rid);
}
}
}
''' <summary>
''' Handles structure-changed events. If a new app window has been added, this method ensures
''' it's in the list of runtime IDs and subscribed to window-close events.
''' </summary>
''' <param name="sender">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
''' <remarks>
''' An exception can be thrown by the UI Automation core if the element disappears
''' before it can be processed -- for example, if a menu item is only briefly visible.
''' This exception cannot be caught here because it crosses native/managed boundaries.
''' In the debugger, you can ignore it and continue execution. The exception does not cause
''' a break when the executable is being run.
''' </remarks>
Private Sub OnStructureChanged(ByVal sender As Object, ByVal e As StructureChangedEventArgs)
Dim element As AutomationElement = DirectCast(sender, AutomationElement)
If e.StructureChangeType = StructureChangeType.ChildAdded Then
Dim myWindowPattern As Object = Nothing
If False = element.TryGetCurrentPattern(WindowPattern.Pattern, myWindowPattern) Then
Return
End If
Dim rid As Integer() = e.GetRuntimeId()
If RuntimeIdListed(rid, savedRuntimeIds) < 0 Then
AddToWindowHandler(element)
savedRuntimeIds.Add(rid)
End If
End If
End Sub
Il codice di esempio seguente aggiunge un'istanza del delegato.
// elementRoot is an AutomationElement.
Automation.AddStructureChangedEventHandler(elementRoot, TreeScope.Children,
new StructureChangedEventHandler(OnStructureChanged));
' elementRoot is an AutomationElement.
Automation.AddStructureChangedEventHandler(elementRoot, TreeScope.Children, New StructureChangedEventHandler(AddressOf OnStructureChanged))
Commenti
eventHandler
può essere un'istanza del metodo o un riferimento al metodo (AddressOf
in Visual Basic).
Si applica a
Vedi anche
- RemoveStructureChangedEventHandler(AutomationElement, StructureChangedEventHandler)
- AddAutomationEventHandler(AutomationEvent, AutomationElement, TreeScope, AutomationEventHandler)
- AddAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler)
- Sottoscrivere gli eventi di automazione interfaccia utente
- Cenni preliminari sugli eventi di automazione interfaccia utente