Partager via


AutomationInteropProvider.RaiseStructureChangedEvent Méthode

Définition

Déclenche un événement lorsque l’arborescence UI Automation a changé.

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)

Paramètres

provider
IRawElementProviderSimple

L’élément associé à l’événement.

e
StructureChangedEventArgs

Informations relatives à l'événement.

Exemples

L’exemple suivant montre comment déclencher un événement lorsque des enfants sont ajoutés ou supprimés dans une zone de liste personnalisée.

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

Remarques

Un exemple de modification dans l’arborescence est l’ajout ou la suppression d’éléments enfants dans une zone de liste, ou l’extension ou la réduction dans une arborescence.

Lorsqu’un élément enfant est supprimé, l’identificateur d’exécution de l’élément ou de son conteneur est passé au StructureChangedEventArgs constructeur. Toutefois, dans la version actuelle d’UI Automation, il n’existe aucun moyen simple pour un instance d’un fournisseur de découvrir son identificateur d’exécution. La GetRuntimeId méthode retourne normalement un tableau qui contient AppendRuntimeId, un nombre magique qui indique au système UI Automation de créer un identificateur unique pour chaque instance du contrôle. La valeur brute fournie par GetRuntimeId ne doit pas être utilisée dans les événements, car elle n’a aucun sens pour les clients et ne peut pas être utilisée pour identifier un instance spécifique.

En raison de cette limitation, les événements de type ChildAdded et ChildRemoved ne sont pas très utiles. En guise d’alternative, utilisez ChildrenBulkAdded toujours et ChildrenBulkRemoved, en passant 0 comme identificateur du runtime. Vous ne pouvez pas utiliser null, car cela déclenche une exception. Les clients seront avertis qu’une modification a été apportée dans le conteneur (identifié par le sender paramètre passé à ), StructureChangedEventHandlersans notification spécifique des enfants qui ont été ajoutés ou supprimés.

S’applique à

Voir aussi