Step By Step Creation Of RadioButton Control In Universal Window App


RadioButton enables the user to select a single option from a group of the choices, when paired with other RadioButton controls. When a user clicks on one RadioButton, it becomes checked and all other RadioButtons with the same group becomes unchecked.


  • Visual Studio 2015

Now let's get started with the following steps:

Step 1 : Create Windows Universal Project

Open Visual Studio 2015 and click File -> New -> Project option for New Universal App.

Create Windows Universal Project

Step 2: Giving the Project Name

New Project Window will open, where you can select an Installed -> Template -> Visual C# -> Windows -> Universal and select a Blank App (Universal Windows).

Type Project Name RadioButtonApp and click OK button.

Giving the Project Name

Step 3: Setting the platform Versions

Here, we choose the Target Version and Minimum Version for our Universal Windows Application and click OK button.

Setting the platform Versions

Step 4: Choose Designer Window

Now, we go to the Solution Explorer and select MainPage.xaml

Step 5 : Designing the App

Drag the RadioButton from the tool box and change the Name to Male, Content to Male and GroupName to Gender in the Property Window.

Designing the App

Place another RadioButton from the tool box and the Name to Female, Content to Female and GroupName to Gender in the Property Window.

Designing the App

Next, drag the button from the Toolbox and change the name to Submit button

Designing the App

Step 6: Add the Coding

To add the coding, double click on the Submit button and add the mentioned source code.

Add the Mentioned Header file

Add the Coding

  1. using Windows.UI.Popups;   
Add the following code in the appropriate place (Submit Button).

  1. Private async void Submitbutton_Click(object sender, RoutedEventArgs e) {  
  2.     if (RadioMale.IsChecked == true) {  
  3.         var dialog = new MessageDialog("You are Selected Male");  
  4.         await dialog.ShowAsync();  
  5.         return;  
  6.     } else {  
  7.         var dialog = new MessageDialog("You are Selected Female");  
  8.         await dialog.ShowAsync();  
  9.         return;  
  10.     }  
  11. }  
Step 7: Run the Application

Now, we are ready to run our project. Thus, click the local machine for running the Application.




Conclusion: I hope you understood RadioButton control in Universal Window and how to run it.

Similar Articles