The event attribute syntax

In XAML, you can also define events for a specific object element. Although it looks like a property attribute, it is used to assign the event. If an 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 backend code of the XAML page. The event implementation for the preceding Button_Click event looks like the following:

void Button_Click(object sender, RoutedEventArgs e) 
{ 
   // event implementation 
} 

In this section, we have discussed object element syntax, property attribute syntax, property element syntax, content syntax, collection syntax, and event attribute syntax, which gave you a basic overview of the XAML syntax to define the UI of the WPF application. In the next section, we will start building our first WPF application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.66.13