AutomationInteropProvider.RaiseStructureChangedEvent Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Abre um evento quando a árvore de Automatização da Interface de Utilizador mudou.
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 seguinte mostra como criar um evento quando crianças são adicionadas ou removidas de uma caixa de lista 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
Observações
Um exemplo de alteração na estrutura da árvore é elementos filhos serem adicionados ou removidos de uma caixa de lista, ou serem expandidos ou colapsados numa vista em árvore.
Quando um elemento filho é removido, o identificador de tempo de execução do elemento ou do seu contentor é passado para o StructureChangedEventArgs construtor. Na versão atual do Automatização da Interface de Utilizador, no entanto, não existe uma forma fácil para uma instância de um fornecedor descobrir o seu identificador em tempo de execução. O método GetRuntimeId normalmente devolve um array que contém AppendRuntimeId, um número mágico que instrui o sistema Automatização da Interface de Utilizador a criar um identificador único para cada instância do controlo. O valor bruto fornecido por GetRuntimeId não deve ser usado em eventos, pois não tem significado para os clientes e não pode ser usado para identificar uma instância específica.
Devido a esta limitação, os eventos do tipo ChildAdded e ChildRemoved não são muito úteis. Como alternativa, use ChildrenBulkAdded sempre e ChildrenBulkRemoved, passando 0 como identificador de tempo de execução. Não pode usar null, pois isso abriria uma exceção. Os clientes serão notificados de que foi feita uma alteração no contentor (identificada pelo sender parâmetro passado para o StructureChangedEventHandler), sem aviso específico sobre que filhos foram adicionados ou removidos.