ContentElement.RaiseEvent(RoutedEventArgs) 方法

定義

引發特定路由事件。Raises a specific routed event. 要引發的 RoutedEvent 是在所提供的 RoutedEventArgs 執行個體內識別 (作為該事件資料的 RoutedEvent 屬性)。The RoutedEvent to be raised is identified within the RoutedEventArgs instance that is provided (as the RoutedEvent property of that event data).

public:
 virtual void RaiseEvent(System::Windows::RoutedEventArgs ^ e);
public void RaiseEvent (System.Windows.RoutedEventArgs e);
abstract member RaiseEvent : System.Windows.RoutedEventArgs -> unit
override this.RaiseEvent : System.Windows.RoutedEventArgs -> unit
Public Sub RaiseEvent (e As RoutedEventArgs)

參數

e
RoutedEventArgs

RoutedEventArgs,包含事件資料,也會識別要引發的事件。A RoutedEventArgs that contains the event data and also identifies the event to raise.

實作

範例

下列範例會建立事件資料,並將事件識別碼附加至資料,然後使用事件資料實例來引發自訂路由事件。The following example creates event data, appends the event identifier to the data, and then uses the event data instance to raise a custom routed event.

void RaiseTapEvent()
{
  RoutedEventArgs newEventArgs = new RoutedEventArgs();
  newEventArgs.RoutedEvent = MyCustomLink.TapEvent;
  //newEvent.SetSource(this);
  RaiseEvent(newEventArgs);
}
Private Sub RaiseTapEvent()
  Dim newEventArgs As New RoutedEventArgs()
  newEventArgs.RoutedEvent = MyCustomLink.TapEvent
  'newEvent.SetSource(Me)
  MyBase.RaiseEvent(newEventArgs)
End Sub

備註

e 參數會輸入為所有路由事件資料的通用基底類型;不過,應該將事件資料指定為可用於引發之事件的最特定事件資料類型,因為 RoutedEventArgs 衍生的類別包含在引發時用於特定事件的實際特定資料屬性。The e parameter is typed as the common base type for all routed event data; however, the event data should be given as the most specific event data type that is available for the event being raised, because RoutedEventArgs derived classes contain the actual specific data properties that are intended for the specific event when it is raised.

RoutedEventArgs 不只是事件的狀態屬性,它也會識別要引發的路由事件。RoutedEventArgs is not just the state properties for the event; it also identifies which routed event to raise. 這個事件引發模式和路由事件資料兩者都不同于 通用語言執行平台 (CLR)common language runtime (CLR) 事件和資料類別,通常只包含與事件相關的屬性。This event-raising pattern and the routed event data both differ from 通用語言執行平台 (CLR)common language runtime (CLR) events and data classes, which typically just contain properties that are related to the event.

適用於