I have a simple scenario - I have a "UserControl" down inside a WPF app. I want it to raise an event and catch that event at the main window, so I can call "show" to ensure the window is shown (e.g. not hidden in the tray).
I understand from here and here that a RoutedEvent is the way to go.
However, it is complicated because I am using ModernUI as a framework to set up the window. It looks great.
However, in MUI, I just populate "mui:LinkGroup.Links" and the rest of the construction of "pages" is handled for me, so I can't seem to figure out how to refer down the logical tree to actually set up a subscriber to the event. The tree is hidden away in however MUI sets everything up.
So - has anyone done this before? Is there a way I can register a handler for a RoutedEvent using MUI?
Or is there some other way of dealing with events propagated up the tree?
Thanks in advance!
Are you implementing MVVM? In that pattern, if based on a framework like Caliburn Micro or Prism you would use an EventAggregator to create a decoupled notification mechanism. If you are not using any of those frameworks you could search for a stand-alone version of an EventAggregator. But make sure that it uses weak references to keep track of the subscribers. I would definitely prefer that approach toward bubbling events.
[EDIT] For MVVMLight you would use the Messenger class. See Laurents article on MSDN Magazine.
It has a Send Method
and a Register method: