WP7 Tutorial 5 : Handling Events from the User Interface

After learning about how to design the user interface we move on to handling the events from the interface. In this Windows Phone 7 tutorial, you will learn how to define the event handlers that respond to actions from the user interface, namely the button click event. You define event handlers using code in the code-behind file of the page.
1. Confirm that the mode of the designer is set to Design. To do this, double-click the Design tab on the right edge of the designer window. If you have trouble identifying the correct tab, position the mouse cursor over each tab to display a tooltip that identifies it.
2. Click the button labeled as “Click me” from the design view of emulator and open the properties tab via pressing F4.
3. In properties, select the Events tab which have list of all the available events possible under that click button (though you can make more). Under the Click event type ClickMeButton_Click in the text box next to the event. Double click or press enter to generate a code behind this event and event handler with this name.
button1 600x319 WP7 Tutorial 5 : Handling Events from the User Interface

xaml WP7 Tutorial 5 : Handling Events from the User Interface
4.  The method implementation (which is an empty method right now) is in the MainPage.xaml.cs file. Insert the following code inside the body of the ClickMeButton_Click method
private void ClickMeButton_Click(object sender, RoutedEventArgs e)
{
    BannerTextBlock.Text = MessageTextBox.Text;
    MessageTextBox.Text = String.Empty;
}

Comments