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
From the course: Windows Presentation Foundation: 3 Events and the Event Model
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understand routed events6m 3s
-
Understand event signatures6m 56s
-
Understand the RoutedEventArgs5m 1s
-
Wire up event handlers in XAML4m 58s
-
Wire up event handlers with the Properties window4m 18s
-
Wire up event handers in code4m 4s
-
Understand event bubbling5m 17s
-
Understand event tunneling3m 51s
-
Suppress events as they traverse the element tree5m 22s
-
-
-
-