How To Work With The CheckBox Control In Universal Window App

CheckBox Button

A CheckBox button enables the user to select more options from a group of choices, when paired with other CheckBox button controls. When a user clicks on a one CheckBox button, it becomes checked. You can click a CheckBox to select it and click it again to deselect it.

Prerequisites

  • 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.

New

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 CheckBoxApp and click OK button. 

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.

Versions

Step 4: Choose Designer Window

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

Step 5 : Designing the App

Drag the CheckBox Button from the tool box and change the name to Boldch and the content to Bold in the Property Window.

Designing the App

Place another CheckBox Button from the tool box and change the name to Italicch and the content to Italic in the Property Window.

Designing the App

Place one more CheckBox button from the tool box and change the name to Underch and the content to Underline in the Property Window.

Designing the App

Next, drag the button from the Tollbox and change the name to Submitbutton.

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 following Header file:

Coding

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

code
  1. private async void Submitbutton_Click(object sender, RoutedEventArgs e) {  
  2.     string msg = "";  
  3.     if (Boldch.IsChecked == true) {  
  4.         msg = "Bold";  
  5.     }  
  6.     if (Italicch.IsChecked == true) {  
  7.         msg = msg + " Italic";  
  8.     }  
  9.     if (Underch.IsChecked == true) {  
  10.         msg = msg + " Underline";  
  11.     }  
  12.     if (msg.Length > 0) {  
  13.         var dialog = new MessageDialog(msg + " selected ");  
  14.         await dialog.ShowAsync();  
  15.         return;  
  16.     } else {  
  17.         var dialog = new MessageDialog("No one Selected");  
  18.         await dialog.ShowAsync();  
  19.         return;  
  20.     }  
  21.     Boldch.IsThreeState = true;  
  22. }  
Step 7: Run the Application

Now, we are ready to run our Project. Thus, click the local machine to run the Application.

Application

Output

Output

Conclusion: I hope you understood Radio button control in Universal Windows and how to run it.


Similar Articles