SIGN UP MEMBER LOGIN:    
ARTICLE

Radio Button Grouping in Silverlight 3 Application

Posted by Diptimaya Patra Articles | XAML with C# July 30, 2009
In this article we will see how we can achieve multi grouping in Silverlight.
Reader Level:
 

Introduction

In this article we will see how we can achieve multi grouping in Silverlight.

Ordinarily, radio buttons are grouped by their container. That means if you place three RadioButton controls in a single StackPanel, they form a group from which you can select just one of the three.

Creating Silverlight Project

Fire up Blend 3 and create a Silverlight Application. Name it as RadioButtonGroupingInSL3.

radio1.gif

Add a Stack Panel into the Grid.

radio2.gif

radio3.gif

Now add three Radio Buttons into Stack Panel Name them as Group 1.

radio4.gif

Now at this point of time if you run your application you will find by default they are grouped, so that only one Radio Button can be selected.

if you place a combination of radio buttons in two separate StackPanel controls, you have two independent groups on your hands.

To achieve multi groping we will add another four Radio Buttons.

This time name them as Gropu 2 and Gropu 3.

radio5.gif

The GroupName property allows you to override this behavior. You can use it to create more than one group in the same container or to create a single group that spans multiple containers. Either way, the trick is simple-just give all the radio buttons that belong together the same group name.

<Grid x:Name="LayoutRoot" Background="White">
            <StackPanel Height="100" VerticalAlignment="Top" Margin="0" Orientation="Horizontal">
                        <StackPanel.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                <GradientStop Color="#FFEC7C7C" Offset="1"/>
                                                <GradientStop Color="White"/>
                                    </LinearGradientBrush>
                        </StackPanel.Background>
                        <RadioButton Content="Gropup 1"/>
                        <RadioButton Content="Gropup 1"/>
                        <RadioButton GroupName="Group2" Content="Gropup 2"/>
                        <StackPanel Orientation="Horizontal">
                                    <RadioButton Content="Group 3"/>
                                    <RadioButton Content="Group 3"/>
                                    <RadioButton Content="Group 3"/>
                                    <RadioButton GroupName="Group2" Content="Group 3"/>
                        </StackPanel>
            </StackPanel>
</
Grid>

Here, there are two containers holding radio buttons, but three groups. The final radio button at the bottom of each group box is part of a third group. In this example, it makes for a confusing design, but there may be some scenarios where you want to separate a specific radio button from the pack in a subtle way without causing it to lose its groupmembership.

Now if you run your application you will find the third Radio Button of the first Stack Panel can be selected too.

radio6.gif

Enjoy Coding.

Login to add your contents and source code to this article
share this article :
post comment
 

This article is copied almost word-for-word from the book Silverlight 2 Visual Essentials, p. 127, by Matthew MacDonald.  Does this violate the Terms and Conditions of this website?

Posted by Alcy May 06, 2010
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor