This video shows how to subscribe to a routed event in C# code. See how to use the standard .NET subscription syntax and the routed-event-specific syntax.
- [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 indicate that you have an event…
- Understanding routed events and event signatures
- Wiring up event handlers
- Event bubbling and tunneling
- Programming mouse events
- Programming keyboard and ink events