AutomationInteropProvider.RaiseStructureChangedEvent Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
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.
Informações sobre o evento.
Exemplos
O exemplo a seguir mostra como gerar um evento quando as crianças são adicionadas ou removidas 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 alteração na estrutura da árvore são elementos filho sendo adicionados ou removidos de uma caixa de listagem ou 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 do Automação da Interface do Usuário, no entanto, não há uma maneira fácil para uma instância de um provedor descobrir seu identificador de runtime. O método GetRuntimeId 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 identifer 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 ChildrenBulkRemovedpasse 0 como o identifer 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 (identificado pelo sender parâmetro passado para o StructureChangedEventHandler), sem aviso prévio específico do que as crianças foram adicionadas ou removidas.
Aplica-se a
Confira também
- StructureChangedEventArgs(StructureChangeType, Int32[])
- Visão geral de eventos de automação da interface do usuário
- Disparar eventos de um provedor de automação de IU