StructureChangedEventArgs(StructureChangeType, Int32[]) 构造函数

定义

初始化类的新实例 StructureChangeType ,指定更改的类型和结构更改的元素的标识符(ID)。

public:
 StructureChangedEventArgs(System::Windows::Automation::StructureChangeType structureChangeType, cli::array <int> ^ runtimeId);
public StructureChangedEventArgs(System.Windows.Automation.StructureChangeType structureChangeType, int[] runtimeId);
new System.Windows.Automation.StructureChangedEventArgs : System.Windows.Automation.StructureChangeType * int[] -> System.Windows.Automation.StructureChangedEventArgs
Public Sub New (structureChangeType As StructureChangeType, runtimeId As Integer())

参数

structureChangeType
StructureChangeType

一个指定更改类型的值。

runtimeId
Int32[]

其结构已更改的UI 自动化元素的运行时标识符(ID)。

示例

以下示例演示如何在向自定义列表框添加或从中删除子级时构造和引发事件。

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

注解

可以在 structureChangeType 中返回的值取决于UI 自动化提供程序的实现。 例如,在 Win32 列表框中添加或删除项时,如果提供程序无法确定添加或删除的项数,则它可能会指定ChildrenInvalidated或不ChildAddedChildRemoved指定。

下表描述了不同 StructureChangedEventHandler 结构更改收到的事件中的信息。

structureChangeType 事件源 runtimeId
ChildAdded 已添加的子级。 已添加的子级。
ChildRemoved 已删除的子级的父级。 已删除的子级。
ChildrenBulkAdded 已添加的子级的父级。 已添加的子级的父级。
ChildrenBulkRemoved 已删除的子级的父级。 已删除的子级的父级。
ChildrenInvalidated 无效的子级的父级。 无效的子级的父级

自定义控件可能无法在 . 中 runtimeId提供有意义的值。 有关详细信息,请参阅 RaiseStructureChangedEvent

适用于

另请参阅