RoutedEventArgs.InvokeEventHandler(Delegate, Object) RoutedEventArgs.InvokeEventHandler(Delegate, Object) RoutedEventArgs.InvokeEventHandler(Delegate, Object) RoutedEventArgs.InvokeEventHandler(Delegate, Object) Method

定義

在衍生類別中覆寫時,提供以特定類型方式叫用事件處理常式的方式,這可透過基底實作來提高效率。When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation.

protected:
 virtual void InvokeEventHandler(Delegate ^ genericHandler, System::Object ^ genericTarget);
protected virtual void InvokeEventHandler (Delegate genericHandler, object genericTarget);
abstract member InvokeEventHandler : Delegate * obj -> unit
override this.InvokeEventHandler : Delegate * obj -> unit
Protected Overridable Sub InvokeEventHandler (genericHandler As Delegate, genericTarget As Object)

參數

genericHandler
Delegate Delegate Delegate Delegate

要叫用的泛型處理常式/委派實作。The generic handler / delegate implementation to be invoked.

genericTarget
Object Object Object Object

應該在其上叫用所提供處理常式的目標。The target on which the provided handler should be invoked.

範例

以下是說明可用於執行之基本模式的虛擬程式碼。The following is pseudocode that illustrates a basic pattern that can be used for implementation. 在這裡MyRoutedEventHandler , 是的子RoutedEventHandler類別。Here, MyRoutedEventHandler is a subclass of RoutedEventHandler.

public class MyRoutedEventArgs : RoutedEventArgs 
{
// other members omitted
    protected override void InvokeEventHandler(Delegate genericHandler, object genericTarget) {
        MyRoutedEventHandler handler = (MyRoutedEventHandler) genericHandler;
        handler(genericTarget, this);
    }
}
Public Class MyRoutedEventArgs
    Inherits RoutedEventArgs
' other members omitted
    Protected Overrides Sub InvokeEventHandler(ByVal genericHandler As System.Delegate, ByVal genericTarget As Object)
        Dim handler As MyRoutedEventHandler = CType(genericHandler, MyRoutedEventHandler)
        handler(genericTarget, Me)
    End Sub
End Class

備註

基底執行會納入反映, 以判斷處理常式不是逐字RoutedEventHandler的任何情況的正確處理常式, 而且此反映步驟的確會造成效能上的影響。The base implementation incorporates reflection to determine the right handler for any case where the handler is not literally RoutedEventHandler, and this reflection step does have some performance consequences. 藉由不依賴反映, 可以更有效率地執行調用。Invocations can be made more efficient by not relying on reflection. 這是應採用此方法的案例, 可供任何選擇覆寫它的路由事件引數類別使用。This is the scenario that motivates this method being available for any routed event arguments class that choose to override it. 因為您的實作為必須負責叫用型別安全處理常式, 所以不應呼叫這個方法的基底。Implementations should not call the base for this method, because your implementation should already be responsible for invoking the type safe handlers.

給繼承者的注意事項

這個方法會被衍生的事件資料類別覆寫, 以提供更有效率的委派調用。This method is intended to be overridden by derived event data classes to provide more efficient invocation of their delegates. 執行應該將提供genericHandler的轉換成特定類型的委派, 然後叫用該處理常式。The implementation should cast the provided genericHandler to the type-specific delegate, and then invoke that handler.

預設的執行會嘗試叫用提供的處理常式, 並嘗試將它RoutedEventHandler轉換成。The default implementation will attempt to invoke the provided handler, attempting to cast it as RoutedEventHandler. 如果將genericTarget null或當做提供, 將會引發例外狀況。 genericHandlerIf either genericHandler or genericTarget is provided as null, exceptions will be raised.

適用於