.netwpfeventsuser-controls

Raising an event on parent window from a user control in .NET C#


The title pretty much explains the question. I have a user control loaded into the main window when the application is first run. What I want to do is to raise an event on parent window when a button on the user control is clicked, so how can I raise a parent event from button1_Click on the user control?


Solution

  • You need a RoutedEvent link

    "Routed events are events which navigate up or down the visual tree acording to their RoutingStrategy. The routing strategy can be bubble, tunnel or direct. You can hook up event handlers on the element that raises the event or also on other elements above or below it by using the attached event syntax: Button.Click="Button_Click"."