Condividi tramite


AutomationInteropProvider.RaiseStructureChangedEvent Metodo

Definizione

Genera un evento quando l'albero Automazione interfaccia utente è stato modificato.

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)

Parametri

provider
IRawElementProviderSimple

Elemento associato all'evento.

e
StructureChangedEventArgs

Informazioni sull'evento.

Esempio

Nell'esempio seguente viene illustrato come generare un evento quando gli elementi figlio vengono aggiunti o rimossi da una casella di riepilogo personalizzata.

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

Commenti

Un esempio di modifica nella struttura ad albero è costituito dall'aggiunta o dalla rimozione di elementi figlio da una casella di riepilogo o espansi o compressi in una visualizzazione albero.

Quando un elemento figlio viene rimosso, l'identificatore di runtime dell'elemento o del relativo contenitore viene passato al StructureChangedEventArgs costruttore. Nella versione corrente di Automazione interfaccia utente, tuttavia, non esiste un modo semplice per individuare l'identificatore di runtime di un'istanza di un provider. Il GetRuntimeId metodo restituisce in genere una matrice che contiene AppendRuntimeId, un numero magico che indica al sistema Automazione interfaccia utente di creare un identificatore univoco per ogni istanza del controllo. Il valore non elaborato fornito da GetRuntimeId non deve essere usato negli eventi, perché è privo di significato per i client e non può essere usato per identificare un'istanza specifica.

A causa di questa limitazione, gli eventi di tipo ChildAdded e ChildRemoved non sono molto utili. In alternativa, usare ChildrenBulkAdded sempre e ChildrenBulkRemoved, passando 0 come identificatore di runtime. Non è possibile usare null, perché genererà un'eccezione. I client riceveranno una notifica che indica che nel contenitore è stata apportata una modifica (identificata dal sender parametro passato a StructureChangedEventHandler), senza preavviso specifico di quali elementi figlio sono stati aggiunti o rimossi.

Si applica a

Vedi anche