Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> Windows Phone >> RadioButton Control in Windows 7 Phone Development
RadioButton Control in Windows 7 Phone Development
RadioButton Control in Windows 7 Phone Development


by Arun Singh on 4/11/2012 10:44:51 PM

Views: 2602       Comments: 0

RadioButton Control in Windows 7 Phone Development

If you want to give few options to users out of which only one of this can be selected, radio buttons are used. Once you define set of radio buttons, you can bind them together using ‘GroupName’ property.

This article is going to explain how to use RadioButton control in windows 7 phone application using c# code.  Let’s see a brief demonstration on it.

1.       Open visual studio and go to File -> New -> Project.

2.       Select Silverlight for Windows Phone option

3.       Enter the project name and choose the saving location

4.       Click on button ‘Ok’

Now drag and drop radio button control from toolbox which is at top left corner.

RadioButton Control in Windows 7 Phone Development

Write down the following code to build the above layout.

Code of ‘MainPage.xaml’:

<!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent" Width="480">

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>

        </Grid.RowDefinitions>

 

        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28" Background="#FF6C1643">

            <TextBlock x:Name="ApplicationTitle" Text="My Application" Style="{StaticResource PhoneTextNormalStyle}"/>

            <TextBlock x:Name="PageTitle" Text="RadioButton Demo" Margin="0,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Height="90" Width="424" FontSize="48" Foreground="#FFE8E8EB" AllowDrop="False" />

        </StackPanel>

 

        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Background="#FF194533">

            <Button Content="Submit" Height="88" HorizontalAlignment="Left" Margin="140,350,0,0" Name="btnSubmit" VerticalAlignment="Top" Width="170" Background="#FF15A7E8" DataContext="{Binding}" AllowDrop="False" UseLayoutRounding="False" VerticalContentAlignment="Center" Click="btnSubmit_Click" />

            <RadioButton Content="Australia" Height="72" Margin="58,74,205,0" Name="rbAustralia" VerticalAlignment="Top" GroupName="gbtnFavourit" BorderBrush="#BF22DE4D" />

            <RadioButton Content="England" Height="72" HorizontalAlignment="Left" Margin="58,152,0,0" Name="rbEngland" VerticalAlignment="Top" GroupName="gbtnFavourit" />

            <RadioButton Content="India" Height="72" HorizontalAlignment="Left" Margin="58,230,0,0" Name="rbIndia" VerticalAlignment="Top" GroupName="gbtnFavourit" />

        </Grid>

    </Grid>

 

Code of ‘MainPage.xaml.cs’:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using Microsoft.Phone.Controls;

 

namespace testPhoneApp

{

    public partial class MainPage : PhoneApplicationPage

    {

        // Constructor

        public MainPage()

        {

            InitializeComponent();

        }

 

        private void btnSubmit_Click(object sender, RoutedEventArgs e)

        {

            if (Convert.ToBoolean(rbAustralia.IsChecked))

            {

                MessageBox.Show("You have selected team Australia!");

            }

            else if (Convert.ToBoolean(rbEngland.IsChecked))

            {

                MessageBox.Show("You have selected team England!");

            }

            else if (Convert.ToBoolean(rbIndia.IsChecked))

            {

                MessageBox.Show("You have selected team India!");

            }

            else

            {

                MessageBox.Show("You have not selected any item!");

            }

           

        }

 

     

      

    }

}

 

 

Now execute your program and you will see following output.

RadioButton Control in Windows 7 Phone Development

Now select any option from above list and click on button ‘Submit’.

RadioButton Control in Windows 7 Phone Development

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Arun SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2670
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.