StructureChangedEventArgs(StructureChangeType, Int32[]) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化類別的新實例 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[]
結構變更的 使用者介面自動化 元素的執行時識別碼(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 回傳的值取決於 使用者介面自動化 提供者的實作。 例如,當 Windows 32 清單框新增或移除項目時,若提供者無法判斷新增或移除項目數量,可能會指定 ChildrenInvalidated 且 不 ChildAdded 指定或 ChildRemoved。
下表描述了不同結構變更時所收到 StructureChangedEventHandler 的事件資訊。
structureChangeType |
事件來源 | runtimeId |
|---|---|---|
| ChildAdded | 那個被加入的孩子。 | 那個被加入的孩子。 |
| ChildRemoved | 被移除孩子的父母。 | 那個被帶走的孩子。 |
| ChildrenBulkAdded | 被加入的孩子們的父母。 | 被加入的孩子們的父母。 |
| ChildrenBulkRemoved | 被帶走的孩子的家長。 | 被帶走的孩子的家長。 |
| ChildrenInvalidated | 被否定孩子的家長。 | 被無效兒童的家長 |
自訂控制項可能無法在 中 runtimeId提供有意義的值。 如需詳細資訊,請參閱RaiseStructureChangedEvent。