Udostępnij przez


AutomationInteropProvider.RaiseStructureChangedEvent Metoda

Definicja

Zgłasza zdarzenie, gdy drzewo automatyzacja interfejsu użytkownika uległo zmianie.

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)

Parametry

provider
IRawElementProviderSimple

Element skojarzony ze zdarzeniem.

e
StructureChangedEventArgs

Informacje o zdarzeniu.

Przykłady

W poniższym przykładzie pokazano, jak zgłosić zdarzenie po dodaniu lub usunięciu elementów podrzędnych z pola listy niestandardowej.

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

Uwagi

Przykładem zmiany struktury drzewa jest dodanie lub usunięcie elementów podrzędnych z pola listy albo rozwinięcie lub zwinięcie w widoku drzewa.

Po usunięciu elementu podrzędnego identyfikator środowiska uruchomieniowego elementu lub jego kontenera jest przekazywany do konstruktora StructureChangedEventArgs . W bieżącej wersji automatyzacja interfejsu użytkownika nie ma jednak łatwego sposobu odnajdywania identyfikatora środowiska uruchomieniowego przez wystąpienie dostawcy. Metoda GetRuntimeId zwykle zwraca tablicę zawierającą AppendRuntimeIdliczbę magiczną, która nakazuje systemowi automatyzacja interfejsu użytkownika utworzenie unikatowego identyfikatora dla każdego wystąpienia kontrolki. Nieprzetworzona wartość podana przez GetRuntimeId program nie powinna być używana w zdarzeniach, ponieważ jest bez znaczenia dla klientów i nie może być używana do identyfikowania określonego wystąpienia.

Ze względu na to ograniczenie zdarzenia typu ChildAdded i ChildRemoved nie są bardzo przydatne. Alternatywnie należy użyć ChildrenBulkAdded funkcji i ChildrenBulkRemoved, przekazując wartość 0 jako identifer środowiska uruchomieniowego. Nie można użyć metody null, ponieważ spowoduje to wystąpienie wyjątku. Klienci zostaną powiadomieni, że w kontenerze wprowadzono zmianę (zidentyfikowaną przez sender parametr przekazany do StructureChangedEventHandlerelementu ), bez powiadomienia o tym, jakie elementy podrzędne zostały dodane lub usunięte.

Dotyczy

Zobacz też