About incident bubbling

zhaozj2021-02-16  41

Defining a bubbling event in the control If you want the control to bubbber, the control is called RaisebubbleEvent from the oneVentname method that triggers the event. Example: Event Command definition of a bubbling protected virtual void OnCommand (CommandEventArgs e) {CommandEventHandler handler = (CommandEventHandler) Events [EventCommand] enabled; if (handler = null!) Handler (this, e); RaiseBubbleEvent (this, e) } Note: Event bubbles are not limited to command events. You can use this mechanism to make any events bubbling

The control is handled on the bubbling event 1. If you don't rewrite onbubbleevent, the event will automatically bubbling to the superior. 2. Rewrite OnbubbleEvent and call the RaiseBubleEvent from OnbubbleEvent, control some processing and continue to bubbber. Example: checking that the type of event parameters after the event bubbling protected override bool OnBubbleEvent (object source, EventArgs e) {if (e is CommandEventArgs) {TemplatedListCommandEventArgs args = new TemplatedListCommandEventArgs (this, source, (CommandEventArgs) e); RaiseBubbleEvent ( THIS, ARGS); RETURN TRUE;} Return False;} 3. Override onbubbleevent to call the OneventName method that causes this bubbling event. Controls that cause bubbling events (enough) usually disclose the bubbling events as top events. Note: There is a parameter in the standard signature of the OneventName method in .NET Framework. However, OnbubbleEvent has two parameters because the event is not defined in the control of the event (origin), but originates from the control; its second parameter is to provide the source.

转载请注明原文地址:https://www.9cbs.com/read-21408.html

New Post(0)