共用方式為


StructureChangedEventArgs(StructureChangeType, Int32[]) 建構函式

定義

初始化 類別的新實例 StructureChangeType ,並指定變更的類型,以及結構變更之專案的識別碼 (識別碼) 。

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[]

執行時間識別碼 (結構變更之消費者介面自動化專案的識別碼) 。

範例

下列範例示範如何在自訂清單方塊新增或移除子系時建構和引發事件。

/// <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 取決於消費者介面自動化提供者的實作。 例如,當專案新增至 Win32 清單方塊或從 Win32 移除專案時,如果提供者無法判斷新增或移除的專案數,它可能會指定 ChildrenInvalidated 而非 ChildAddedChildRemoved

下表描述 針對 StructureChangedEventHandler 不同結構變更所收到的 事件中的資訊。

structureChangeType 事件來源 runtimeId
ChildAdded 已新增的子系。 已新增的子系。
ChildRemoved 已移除之子系的父系。 已移除的子系。
ChildrenBulkAdded 已加入之子系的父系。 已加入之子系的父系。
ChildrenBulkRemoved 已移除之子系的父系。 已移除之子系的父系。
ChildrenInvalidated 無效之子系的父系。 已失效之子系的父系

自訂控制項可能無法在 中 runtimeId 提供有意義的值。 如需詳細資訊,請參閱RaiseStructureChangedEvent

適用於

另請參閱