Saturday, February 19, 2011

How can I raise an event from anywhere in my WPF application?

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.

From stackoverflow

0 comments:

Post a Comment