Quickstart4
This sample shows you how to implement a button with an associated
Click Event Handler.
This example describes how to bind background events to a XAML button.
XAML Code : < Page
Xmlns = " Http://schemas.microsoft.com/winfx/2006/xaml/presentation "
Xmlns: x = " Http://schemas.microsoft.com/winfx/2006/xaml "
X: Class = " Quickstart_4.page1 " >
< Stackpanel >
< Button horizontalalignment = " Left "
Width = " 100 "
Margin = " 10, 10, 10 "
Click = " Handleclick "
Name = " Button1 " > Click me </ Button >
</ Stackpanel >
</ Page >
Background code: Namespace Quickstart_4
{
Public Partial Class Page1: Page
{
Void Handleclick ( Object Sender, routedeventargs E)
{
Button1.content= "Hello World";
}
}
}
The analysis is as follows:
The page tag of the XAML code, X: class = "quickstart_4.page1", specifies that the XAML file will be compiled into quickstart_4.page1 (The XAML file without this attribute is dynamically compiled at runtime ). Use the Click Event of the button to specify the corresponding method in the background.
Note that the background code event method uses the routedeventargs parameter, which involves the new event mechanism in WPF.