RadioButton
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.
Prerequisites
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]()
Add the following code in the appropriate place (Submit Button).
- Private async void Submitbutton_Click(object sender, RoutedEventArgs e) {
- if (RadioMale.IsChecked == true) {
- var dialog = new MessageDialog("You are Selected Male");
- await dialog.ShowAsync();
- return;
- } else {
- var dialog = new MessageDialog("You are Selected Female");
- await dialog.ShowAsync();
- return;
- }
- }
Step 7: Run the Application
Now, we are ready to run our project. Thus, click the local machine for running the Application.
Output
Conclusion: I hope you understood RadioButton control in Universal Window and how to run it.