开发者

Reregistering a handler for an event, with inheritance (add additional behavior to a handler from a base class)

开发者 https://www.devze.com 2023-04-04 10:23 出处:网络
If I inherit from a base class that handles some event like LeftMouseDownButton, and I rere开发者_开发知识库gister another handler for the same event, would both handlers be invoked (if I set e.Handle

If I inherit from a base class that handles some event like LeftMouseDownButton, and I rere开发者_开发知识库gister another handler for the same event, would both handlers be invoked (if I set e.Handled=false). So I want both the behavior of the handler of the base class and my handler to be invoked? That is I want to add some additional behavior to the base handler


Your would be better to avoid having multiple handlers invoked.

If you have access to the source code of the base class then you can make the handler a virtual method and then override it in the derived class. Have the derived class call the base class so you have the base class functionality execute and then tag on your extra actions afterwards. If you do not have access to the source code of the base class then I guess you are stuck having to add an additional handler and it is likely the base class handler will be invoked before your own handler because it will have been registered first.

0

精彩评论

暂无评论...
验证码 换一张
取 消