Monday, May 11, 2009

How to use the radiobutton in WPF and XAML

WPF RadioButton Control:

RadioButton controls are usually grouped together to offer user a single choice among several options (only one button at a time can be selected).

tag is used too create the radio button in XAML.

In the following tag I create the RadioButton in which Height is height of the RadioButton, Name is the nameof the RadioButton, text in the between the RadioButton tag is the centent visibile to user. Background the the color of the box, Borderbrush is the color of the border, Forground is the color of the text. Articles

To change the orientation from left to right use the FlowDirection property to RightToLeft.

RadioButton is used in the group so that user can select only one option from the available options (No extra coding is required to uncheck others). Use same GroupName of the radiobuttons to mark in a group so that only one option can be selected as follows. Articles
C# Articles Articles
SQL Server 2005 Articles


Now write the code to the handler so that we can take appropriate action on these events in windows1.xaml.cs.

Finding out which radiobutton is checked use the property IsChecked as follows in the btnShow button

private void btnShow_Click(object sender, RoutedEventArgs e)
if (RadioButton_Option1.IsChecked==true)

else if(RadioButton_Option2.IsChecked==true)
else if(RadioButton_Option3.IsChecked==true)
else if(RadioButton_Option4.IsChecked==true)


Summary: Radio button is very simple control and used for selecting only one option from the available options.

No comments:

Post a Comment

Locations of visitors to this page