AutomationInteropProvider.RaiseStructureChangedEvent Método

Definição

Gera um evento quando a árvore de Automação da Interface do Usuário é alterada.

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

O elemento associado ao evento.

e
StructureChangedEventArgs

Informações sobre o evento.

Exemplos

O exemplo a seguir mostra como gerar um evento quando os filhos são adicionados ou removidos de uma caixa de listagem personalizada.

/// <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

Comentários

Um exemplo de uma alteração na estrutura de árvore são elementos filho sendo adicionados ou removidos de uma caixa de listagem ou sendo expandidos ou recolhidos em um modo de exibição de árvore.

Quando um elemento filho é removido, o identificador de runtime do elemento ou de seu contêiner é passado para o StructureChangedEventArgs construtor. Na versão atual da Automação da Interface do Usuário, no entanto, não há uma maneira fácil de uma instância de um provedor descobrir seu identificador de runtime. O GetRuntimeId método normalmente retorna uma matriz que contém AppendRuntimeId, um número mágico que instrui o sistema de Automação da Interface do Usuário a criar um identificador exclusivo para cada instância do controle. O valor bruto fornecido por GetRuntimeId não deve ser usado em eventos, pois não tem sentido para os clientes e não pode ser usado para identificar uma instância específica.

Devido a essa limitação, os eventos do tipo ChildAdded e ChildRemoved não são muito úteis. Como alternativa, sempre use ChildrenBulkAdded e ChildrenBulkRemoved, passando 0 como o identificador de runtime. Você não pode usar null, pois isso gerará uma exceção. Os clientes serão notificados de que uma alteração foi feita no contêiner (identificada pelo sender parâmetro passado para o StructureChangedEventHandler), sem aviso específico de quais filhos foram adicionados ou removidos.

Aplica-se a

Confira também