开发者

Passing event to another class

开发者 https://www.devze.com 2023-02-20 15:44 出处:网络
I have a class that inherits from a base class. This base class exposes an event that can be handled within the child class. I\'m trying to create a library which is as de-coupled as possible and was

I have a class that inherits from a base class. This base class exposes an event that can be handled within the child class. I'm trying to create a library which is as de-coupled as possible and was wondering how I can program it so that I can instantiate my library object within the child class but route the inherited event into the the library object.

Specifically, I'm creating a Windows Phone 7 project in Silverlight. I have a standard XAML page and am handling the Touch.FrameReported event. What I'd like to do is have my external library object handle the Tou开发者_运维技巧ch.FrameReported event on behalf of any page that instantiates it. This way, any new page I create that instantiates my library object can have that library object handle the event rather than copying the handling code in every XAML page.

I hope my post isn't confusing :)


Have you considered using something like the EventAggregator found in PRISM v4 or the Messenger in MVVM Light. Both would provide an event messaging infrastructure allowing you to decouple your views.

0

精彩评论

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

关注公众号