views:

34

answers:

1

I want to achieve a simple Subscribe/Publish mechanism within a WPF application so i can subscribe to events from different places in the application specifying the event type and handler method, and then when publishing the event, my mechanism will call all the subscribed methods on the subscribers. I cannot use the RoutedEvent as I want to raise events freely without being forced to the visual tree.

I am able to achieve the above using c# reflection. But as I am pretty new to c# and WPF(coming from Java), I want to be sure that this is the preferred way.

Is It ??

Many Thanks,

+1  A: 

It looks like you want the "Event Aggregator" pattern from the Prism framework. Surely you can implement it by yourself, although I don't see why you might need reflection for it.

Konstantin Oznobihin
Exactly what i was looking for! I have already implemented such, i just need to replace the reflection usage i did with the use of the Action class which could be used to pass a reference to the subsriber method.Is 'EventAggregator' availble for download as a library? Or is it just a pattern? Thank you.
OrPaz
It's implemented in the Prism framework (see a link for it in my answer) which is available for download from codeplex.com.
Konstantin Oznobihin