|
|
Questions and answers for Concepts Routed Events .
|
5. Concepts Routed Events
|
| 5.1 What is a
Routed event?
|
| 5.2 How can I
handle the input event through XAML?
|
5.1 What is a Routed event?
|
|
In a typical WPF application, it contains many elements. These elements exist in
an element tree relationship with each other. A routed event is a type of event
that can invoke handlers on multiple listeners in an element tree, rather than
just on the object that raised the event.
-
Bubbling: Event handlers on the event source are invoked.
-
Direct: Only the source element itself is given the opportunity to invoke
handlers in response.
-
Tunneling: Initially, event handlers at the element tree root are invoked.
|
5.2 How can I handle the input event through XAML?
|
| To receive input on an element, an event handler must be associated with that
particular event. In XAML the markup is defined and its event handler must be
written in code (such as C# / VB in a code-behind file).
|
[XAML]
<button click="button1_Click" />
|
|
|
|
[C#]
void Button1_Click(object sender, RoutedEventArgs args)
{
//logic to handle the Click event
...
}
|
|