We help IT Professionals succeed at work.
Get Started

Raising Events in WPF

Last Modified: 2012-06-27
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
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE