Friday, March 16, 2012

RadioButton List Using Silverlight

              Need to create radio button list so that user can select one option from the given list of the collections.

             The solution to the above problem is very simple if you read my last post how to create checkbox list control. We will use similar approach as we have used in the create checkbox list control. You can see the output in the Image 1 as shown below, here you can see that I have list of customer from where user can select one of the customers and the selected customer is displayed at the end of the list.

Image 1

The xaml code for creating the radio button list is similar to the checkbox list but what we need to replace the checkbox control with the radio button control (as in case of radio button we know that radio button is used to select only one option from the group of radio button so we don’t need to have the All option (for selecting all the options) which we created for the checkbox list). So in the List 1 you can see only the Item control which contains the radio buttons in its item template so that we have the radio button list for the user to select the option.

List 1

There is not much in the home view model (view model for the home view, views are located in the view folder and view models are located in the viewModel folder). Just based on the property changed event for the particular radio button I just display the serial number and the full name of the record which is currently selected by the user. You can download the source code of the sample from here.

All and any comments / bugs / suggestions are welcomed!