If you’re adding an event handler from code, rather than specifying the handler in XAML, you can just use the += notation for an event that is defined for the control in question. For example, the Button control defines a Click control, so you can do the following:
myButton.Click += new RoutedEventHandler(Button_Click);
But let’s say that you want to add a handler for the Click event to a StackPanel control, which does not define the Click event, and you want to do it from code. You can then use the AddHandler syntax:
myStackPanel.AddHandler(ButtonBase.ClickEvent, (RoutedEventHandler)HandleTheClick);
Read more: 2,000 Things You Should Know About WPF
QR: