- Mastering Visual Studio 2017
- Kunal Chowdhury
- 103字
- 2025-04-04 18:47:06
Event attribute syntax
In XAML, you can also define events for a specific object element. Though it looks like property attribute, but is used to assign the event. If the attribute value of an element is the name of an event, it is treated as an event. In the following code snippet, the Click attribute defines the click event of the buttons:
<Button Click="Button_Click">Click Here</Button> <Button Click="Button_Click" Content="Click Here" />
The implementation of the event handler is generally defined in the code behind of the XAML page. The event implementation for the preceding button click event looks like this:
void Button_Click(object sender, RoutedEventArgs e) { // event implementation }