Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add event handler programmatically in WPF like one can do in Winform

Tags:

What's the equivalent of this winform instruction:

this.button1.Click += new System.EventHandler(this.button1_Click); 

in WPF ?

Update: also for a slider. And what namespace should I declare ?

My point is NOT to use XAML.

like image 981
user310291 Avatar asked Jan 11 '11 22:01

user310291


People also ask

How you can add an event handler?

Right-click the control for which you want to handle the notification event. On the shortcut menu, choose Add Event Handler to display the Event Handler Wizard. Select the event in the Message type box to add to the class selected in the Class list box.

Which method would you call on a user interface UI element to add a new event handler to the current handler collection?

The UIElement. AddHandler method, together with the AddressOf operator to reference the event handler.


1 Answers

Something like this...

this.btnTest.Click+=new RoutedEventHandler(btnTest_Click); 
like image 57
ChrisNel52 Avatar answered Sep 19 '22 11:09

ChrisNel52