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.

Properties:
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.

ASP.net 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.


ASP.net Articles
C# Articles
ADO.net Articles
SQL Server 2005 Articles






Events:


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)

System.Diagnostics.Process.Start(@"http://www.eggheadcafe.com/ASPNetBlog.aspx");
else if(RadioButton_Option2.IsChecked==true)
System.Diagnostics.Process.Start(@"http://www.eggheadcafe.com/CSharpBlog.aspx");
else if(RadioButton_Option3.IsChecked==true)
System.Diagnostics.Process.Start(@"http://www.eggheadcafe.com/ADONetBlog.aspx");
else if(RadioButton_Option4.IsChecked==true)
System.Diagnostics.Process.Start(@"http://www.eggheadcafe.com/SQLServerBlog.aspx");


}

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