Sdílet prostřednictvím


AutomationInteropProvider.RaiseStructureChangedEvent Metoda

Definice

Vyvolá událost při změně stromu automatizace uživatelského rozhraní.

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

Prvek přidružený k události.

e
StructureChangedEventArgs

Informace o události

Příklady

Následující příklad ukazuje, jak vyvolat událost, když jsou do vlastního seznamu přidány nebo odebrány podřízené položky.

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

Poznámky

Příkladem změny ve stromové struktuře je přidání nebo odebrání podřízených prvků ze seznamu nebo rozbalení či sbalení ve stromovém zobrazení.

Při odebrání podřízeného elementu se konstruktoru předá identifikátor modulu runtime elementu nebo jeho kontejneru StructureChangedEventArgs . V aktuální verzi automatizace uživatelského rozhraní však neexistuje snadný způsob, jak instance zprostředkovatele zjistit identifikátor modulu runtime. Metoda GetRuntimeId obvykle vrací pole, které obsahuje AppendRuntimeId, magické číslo, které dává pokyn systému automatizace uživatelského rozhraní vytvořit jedinečný identifikátor pro každou instanci ovládacího prvku. Nezpracovaná hodnota, kterou GetRuntimeId poskytuje, by se neměla používat v událostech, protože je pro klienty bezvýznamná a nedá se použít k identifikaci konkrétní instance.

Vzhledem k tomuto omezení nejsou události typu ChildAdded a ChildRemoved příliš užitečné. Jako alternativu vždy používejte ChildrenBulkAdded a , ChildrenBulkRemovedpředání 0 jako identifikátor modulu runtime. Nemůžete použít null, protože tím dojde k výjimce. Klienti budou upozorněni, že v kontejneru byla provedena změna (identifikovaná parametrem sender předaný do StructureChangedEventHandler), bez konkrétního upozornění, které podřízené položky byly přidány nebo odebrány.

Platí pro

Viz také