Adding user options with radio buttons and checkboxes
Radio buttons and check boxes have a vital role in Windows Application Development. They are mostly used to provide the user an option to select from a group of items. Radio buttons allow you to select one from a group of options, whereas a checkbox allows you to toggle an option.
In this recipe, we will learn how to use RadioButton
and CheckBox
controls in the WPF application.
Getting ready
To get started, open your Visual Studio IDE, and create a new project named CH02.OptionSelectorsDemo
. Make sure you select the WPF application project template.
How to do it...
Open the MainWindow.xaml
page, and follow these steps to add a set of radio buttons and checkbox controls to it:
- First, replace the default
Grid
panel with aStackPanel
to hold items stacked vertically. - Now add the following
StackPanel
with a set of radio buttons with aGroupName="rdoGroup1"
:
<StackPanel Orientation="Horizontal"> <RadioButton GroupName="rdoGroup1" ...