Hope you are enjoying our Windows Phone app development tutorial series! In last tutorial, we learnt more about Silverlight layout controls; now in this tutorial we will learn about Silverlight events and input controls.
To start with an event, let’s understand first what an event is! An event is any method that is executed when user interacts with our application. Each control has a number of events it can respond to. So as a developer we can choose any event provided by that control. If you want to see all the events exhibited by any control just place that control on designer area and go to properties window. Besides that property tab, you will see another tab named “Events”. On clicking that tab, you will see all the events that can be used for that specific control.
Each control has a default event assigned to it, for example, button has a click event assigned to it. There is a simple method using which we can access default method of that control. All you’ve to do is double-click on that control; automatically C# windows will open with the default event definition written. XAML file and C# file are linked together for this purpose. XAML file defines the name of the event handler and C# file defines the action.
Some events are triggered by actions performed by users, for example, clicking on a button while some events are triggered by something that application does for example, starting any application triggers “Loaded” event. As a developer, it’s up to you which ones to use and which ones should be ignored.
Okay, now let us turn towards input controls.
Up till now, we have just seen all standard events. Let’s now study some advance events. Here are some controls which are important for any application.
- Password Box: Password box is very similar to text box but with two differences. Everything typed in this password box is displayed in “dots” or in some character format so as to hide the password. The password box exhibits password property against the text property of textbox.
- Checkbox: Suppose we want to limit the users reply to just “yes” or “no” then we can do that using checkboxes. The checkbox has a “content” property which displayed text next to checkbox. The checkbox has default property known as “checked”.
- Radio buttons: If you want to give few options to users out of which only one of this can be selected, radio buttons are used. Once you define set of radio buttons, you can bind them together using “GroupName” property. So only one radio button can be selected within a group.
- ListBox control: If you want to present user with a list of options and want user to select one or more choices and later retrieve them, you can use list box. ListBox exhibits “selection changed” as its default property. You can add more items to list using property windows or through code using “ListBoxItem.Content” property.
These are some input controls which can do a lot of things. Obviously, there are many more other controls on toolbar but covering all of them is outside the scope of this tutorial series. Meanwhile you can learn more things about these controls. In our next tutorial we will talk about Image Control in Silverlight.