Raising Events in WPF

monserob used Ask the Experts™
I want to raise events from a user control and no matter how much I read up on routed events in WPF I just can't seem to get my head totally around them.

I've just about figured out how to raise an event from a user control and handle that event in the parent window but in one particular scenario the user control is actually contained within another user control which is then contained within a parent window. Is it a case of raising the event in the user control, catching it in the parent user control and raising it again to be caught in the parent window?

Also, I've been using code similar to the below; what does this do? The reason I ask is that my events still seem to fire if I comment this out so I'm not sure what the purpose of this is

    Public Custom Event PaymentDetailsChanged As PaymentDetailsChangedHandler
        AddHandler(ByVal value As PaymentDetailsChangedHandler)
            Me.AddHandler(PaymentDetailsChangedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As PaymentDetailsChangedHandler)
            Me.RemoveHandler(PaymentDetailsChangedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As PaymentDetailsChangedArgs)
        End RaiseEvent
    End Event

Any suggestions of what I should actually be doing would be great, code examples preferably in VB.Net
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Meir RivkinFull stack Software Engineer

why not trying more generic approach something like EventBroker,
check http://www.codeproject.com/Articles/30066/EventBroker-a-notification-component-for-synchrono
Thanks but the EventBroker looks a little overkill for what I'm trying to achieve.

In the end I managed to get things working; instead of adding an event handler that pointed at the shared event through the class that contained it I was actually trying to use an instance of the class.

I've attached a sample app of what I've done; if anyone cares to comment then great, otherwise it might be of use to someone else



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial