Skip to content

Commit 62c7a90

Browse files
Merge pull request #887 from AvaloniaUI/878-docs-for-routed-events-contain-misleading-sections
Fix typos and enhance clarity in routed-events.md
2 parents ee7fffc + 1654faa commit 62c7a90

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/concepts/input/routed-events.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ Most events in Avalonia are implemented as Routed Events. Routed events are even
1010

1111
## What Is a Routed Event
1212

13-
A typical Avalonia application contains many elements. Whether created in code or declared in XAML, these elements exist in an element tree relationship to each other. The event route can travel in one of two directions depending on the event definition, but generally the route travels from the source element and then "bubbles" upward through the element tree until it reaches the element tree root (typically a page or a window). This bubbling concept might be familiar to you if you have worked with the HTML DOM previously.
13+
A typical Avalonia application contains many elements. Whether created in code or declared in XAML, these elements exist in an element tree representing their relationship to each other. The event route can travel in one of two directions depending on the event definition, but generally the route travels from the source element and then "bubbles" upward through the element tree until it reaches the element tree root (typically a page or a window). This bubbling concept might be familiar to you if you have worked with the HTML DOM previously.
1414

1515
### Top-level Scenarios for Routed Events
1616

1717
The following is a brief summary of the scenarios that motivated the routed event concept, and why a typical CLR event was not adequate for these scenarios:
1818

1919
**Control composition and encapsulation:** Various controls in Avalonia have a rich content model. For example, you can place an image inside of a `Button`, which effectively extends the visual tree of the button. However, the added image must not break the hit-testing behavior that causes a button to respond to a `Click` of its content, even if the user clicks on pixels that are technically part of the image.
2020

21-
**Singular handler attachment points:** In Windows Forms, you would have to attach the same handler multiple times to process events that could be raised from multiple elements. Routed events enable you to attach that handler only once, as was shown in the previous example, and use handler logic to determine where the event came from if necessary. For instance, this might be the handler for the previously shown XAML:
21+
**Singular handler attachment points:** In Windows Forms, you would have to attach the same handler multiple times to process events that could be raised from multiple elements. Routed events enable you to attach a handler only once, as shown in this example:
22+
23+
```xml
24+
<Border Height="50" Width="300">
25+
<StackPanel Orientation="Horizontal" Button.Click="CommonClickHandler">
26+
<Button Name="YesButton">Yes</Button>
27+
<Button Name="NoButton">No</Button>
28+
<Button Name="CancelButton">Cancel</Button>
29+
</StackPanel>
30+
</Border>
31+
```
2232

2333
```csharp
2434
private void CommonClickHandler(object sender, RoutedEventArgs e)
@@ -199,7 +209,7 @@ The Avalonia input system uses attached events extensively. However, nearly all
199209

200210
## Qualified Event Names in XAML
201211

202-
Another syntax usage that resembles _typename_._eventname_ attached event syntax but is not strictly speaking an attached event usage is when you attach handlers for routed events that are raised by child elements. You attach the handlers to a common parent, to take advantage of event routing, even though the common parent might not have the relevant routed event as a member. Consider this example again:
212+
Another syntax usage that resembles _typename_._eventname_ attached event syntax but is not strictly speaking an attached event usage is when you attach handlers for routed events that are raised by child elements. You attach the handlers to a common parent, to take advantage of event routing, even though the common parent might not have the relevant routed event as a member. Consider this example again, which you [examined earlier on this page](#top-level-scenarios-for-routed-events).
203213

204214
```xml
205215
<Border Height="50" Width="300">

0 commit comments

Comments
 (0)