AutomationInteropProvider.RaiseStructureChangedEvent メソッド

定義

UI オートメーション ツリーが変更されたときにイベントを発生させます。

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)

パラメーター

provider
IRawElementProviderSimple

イベントに関連付けられている要素。

e
StructureChangedEventArgs

イベントに関する情報。

次の例は、子がカスタム リスト ボックスに追加または削除されたときにイベントを発生させる方法を示しています。

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

注釈

ツリー構造の変更の例として、子要素がリスト ボックスに追加または削除されたり、ツリー ビューで展開または折りたたまれたりする場合があります。

子要素が削除されると、要素またはそのコンテナーのランタイム識別子が、 StructureChangedEventArgs コンストラクターに渡されます。 ただし、UI オートメーションの現在のバージョンでは、プロバイダーのインスタンスがランタイム識別子を検出する簡単な方法はありません。 GetRuntimeId メソッドは通常、AppendRuntimeIdを含む配列を返します。これは、コントロールのすべてのインスタンスに対して一意の識別子を作成するようにUI オートメーション システムに指示するマジックナンバーです。 GetRuntimeIdによって提供される生の値は、クライアントには意味がなく、特定のインスタンスを識別するために使用できないため、イベントでは使用しないでください。

この制限のため、型 ChildAddedChildRemoved のイベントはあまり役に立ちません。 代わりに、常に ChildrenBulkAddedChildrenBulkRemovedを使用し、ランタイム identifer として 0 を渡します。 nullを使用することはできません。これにより例外が発生します。 クライアントには、追加または削除された子の具体的な通知なしに、コンテナー (StructureChangedEventHandlerに渡された sender パラメーターによって識別される) で変更が行われていることが通知されます。

適用対象

こちらもご覧ください