From the course: Windows Presentation Foundation: 3 Events and the Event Model

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Wire up event handers in code

Wire up event handers in code

From the course: Windows Presentation Foundation: 3 Events and the Event Model

Start my 1-month free trial

Wire up event handers in code

- [Instructor] In this example I'll look at how to subscribe to an event in C Sharp only. I won't use anything in my XAML to set up the event handler. You can see in my XAML on line 18 I have an image element, and there's nothing in this element that's specifying an event handler, for the MouseUp event. I'll do all that in code. The most common place that you wire up your event handlers is in the class constructor, so as soon as this class is constructed, this window class, it'll have the event handler in position ready to go. I already have a method written down here. It's the same method I've used in some of my other examples so I'll go ahead and use this one. I'll come up here, the name of my element is called food image so I'll type that in and then the dot operator. Here's the auto-complete list and you can see the events listed here in the auto-completion list with the lightening bolt on the left side of the screen. So I'll choose the MouseUp event, and then in C sharp you…

Contents