AutomationInteropProvider.RaiseStructureChangedEvent Método

Definición

Genera un evento cuando el árbol de automatización de la interfaz de usuario ha cambiado.

public:
 static void RaiseStructureChangedEvent(System::Windows::Automation::Provider::IRawElementProviderSimple ^ provider, System::Windows::Automation::StructureChangedEventArgs ^ e);
public static void RaiseStructureChangedEvent (System.Windows.Automation.Provider.IRawElementProviderSimple provider, System.Windows.Automation.StructureChangedEventArgs e);
static member RaiseStructureChangedEvent : System.Windows.Automation.Provider.IRawElementProviderSimple * System.Windows.Automation.StructureChangedEventArgs -> unit
Public Shared Sub RaiseStructureChangedEvent (provider As IRawElementProviderSimple, e As StructureChangedEventArgs)

Parámetros

provider
IRawElementProviderSimple

Elemento asociado al evento.

e
StructureChangedEventArgs

Información acerca del evento.

Ejemplos

En el ejemplo siguiente se muestra cómo generar un evento cuando se agregan o quitan elementos secundarios de un cuadro de lista personalizado.

/// <summary>
/// Responds to an addition to the UI Automation tree structure by raising an event.
/// </summary>
/// <param name="list">
/// The list to which the item was added.
/// </param>
/// <remarks>
/// For the runtime Id of the item, pass 0 because the provider cannot know
/// what its actual runtime Id is.
/// </remarks>
public static void OnStructureChangeAdd(CustomListControl list)
{
    if (AutomationInteropProvider.ClientsAreListening)
    {
        int[] fakeRuntimeId = { 0 };
        StructureChangedEventArgs args =
            new StructureChangedEventArgs(StructureChangeType.ChildrenBulkAdded, 
            fakeRuntimeId);
        AutomationInteropProvider.RaiseStructureChangedEvent(
            (IRawElementProviderSimple)list.Provider, args);
    }
}

/// <summary>
/// Responds to a removal from the UI Automation tree structure 
/// by raising an event.
/// </summary>
/// <param name="list">
/// The list from which the item was removed.
/// </param>
/// <remarks>
/// For the runtime Id of the list, pass 0 because the provider cannot know
/// what its actual runtime ID is.
/// </remarks>
public static void OnStructureChangeRemove(CustomListControl list)
{
    if (AutomationInteropProvider.ClientsAreListening)
    {
        int[] fakeRuntimeId = { 0 };
        StructureChangedEventArgs args =
            new StructureChangedEventArgs(StructureChangeType.ChildrenBulkRemoved, 
            fakeRuntimeId);
        AutomationInteropProvider.RaiseStructureChangedEvent(
            (IRawElementProviderSimple)list.Provider, args);
    }
}
''' <summary>
''' Responds to an addition to the UI Automation tree structure by raising an event.
''' </summary>
''' <param name="list">
''' The list to which the item was added.
''' </param>
''' <remarks>
''' For the runtime Id of the item, pass 0 because the provider cannot know
''' what its actual runtime Id is.
''' </remarks>
Public Shared Sub OnStructureChangeAdd(ByVal list As CustomListControl)
    If AutomationInteropProvider.ClientsAreListening Then
        Dim fakeRuntimeId(1) As Integer
        fakeRuntimeId(0) = 0
        Dim args As New StructureChangedEventArgs( _
            StructureChangeType.ChildrenBulkAdded, fakeRuntimeId)
        AutomationInteropProvider.RaiseStructureChangedEvent( _
            CType(list.Provider, IRawElementProviderSimple), args)
    End If

End Sub


''' <summary>
''' Responds to a removal from the UI Automation tree structure by raising an event.
''' </summary>
''' <param name="list">
''' The list from which the item was removed.
''' </param>
''' <remarks>
''' For the runtime Id of the list, pass 0 because the provider cannot know
''' what its actual runtime ID is.
''' </remarks>
Public Shared Sub OnStructureChangeRemove(ByVal list As CustomListControl)
    If AutomationInteropProvider.ClientsAreListening Then
        Dim fakeRuntimeId(1) As Integer
        fakeRuntimeId(0) = 0
        Dim args As New StructureChangedEventArgs( _
            StructureChangeType.ChildrenBulkRemoved, fakeRuntimeId)
        AutomationInteropProvider.RaiseStructureChangedEvent( _
            CType(list.Provider, IRawElementProviderSimple), args)
    End If

End Sub

Comentarios

Un ejemplo de cambio en la estructura de árbol es los elementos secundarios que se agregan o quitan de un cuadro de lista, o se expanden o contraen en una vista de árbol.

Cuando se quita un elemento secundario, el identificador en tiempo de ejecución del elemento o de su contenedor se pasa al StructureChangedEventArgs constructor. Sin embargo, en la versión actual de automatización de la interfaz de usuario, no hay ninguna manera fácil de que una instancia de un proveedor detecte su identificador en tiempo de ejecución. Normalmente, el GetRuntimeId método devuelve una matriz que contiene AppendRuntimeId, un número mágico que indica al sistema de automatización de la interfaz de usuario que cree un identificador único para cada instancia del control. El valor sin procesar proporcionado por GetRuntimeId no debe usarse en eventos, ya que no tiene sentido para los clientes y no se puede usar para identificar una instancia específica.

Debido a esta limitación, los eventos de tipo ChildAdded y ChildRemoved no son muy útiles. Como alternativa, use ChildrenBulkAdded siempre y ChildrenBulkRemoved, pasando 0 como identificador en tiempo de ejecución. No se puede usar null, ya que esto generará una excepción. Se notificará a los clientes que se ha realizado un cambio en el contenedor (identificado por el sender parámetro pasado a StructureChangedEventHandler), sin previo aviso específico de lo que se han agregado o quitado los elementos secundarios.

Se aplica a

Consulte también