I have a base page, BasePage, that raises an event that displays messages to the user. Works great on all pages derived from BasePage. I want to do the same thing from user controls, but they don't inherit from BasePage.
What I want is a central place that I can call from anywhere and in that code it will raise an event. Where is a good place to put this code:
public void DisplayMessage(string message)
{
RaiseEvent(new MessageNotificationEventArgs(MessageNotificationEvent, message));
}
so that I can call it from anywhere? RaiseEvent is in the UIElement class, so it needs to go somewhere that is a UIElement.
-
Instead of using events to do this, you should be using Commanding - Josh Smith wrote a great article on this: http://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/
-
One solution to problem is to use an Event Aggregator. The pattern itself is platform independent.
Jeremy Miller has a post about building your own event aggregator here.
However, Composite WPF (formerly Prism) does this and it's optimized for WPF. The specifics can be found here.
0 comments:
Post a Comment