Use StackPanel to Hold RadioButtons

image_pdfimage_print


   
      
<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Use Radio Buttons" Height="300" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*" />
            <ColumnDefinition Width="50*" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0" Margin="2">
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
        </StackPanel>
        <StackPanel Grid.Column="1" Margin="2">
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
            <RadioButton Margin="5">RadioButton</RadioButton>
        </StackPanel>
    </Grid>
</Window>

   
    
    
    
    
    
     


Circled Radio Buttons

image_pdfimage_print


   
      
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Page.Resources>
        <ControlTemplate x:Key="newradio" 
                         TargetType="{x:Type RadioButton}">
            <Border Name="border" BorderBrush="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                    Padding="10"
                    CornerRadius="100">
                <ContentPresenter />
            </Border>

            <ControlTemplate.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter TargetName="border"
                            Property="BorderThickness"
                            Value="3" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Page.Resources>

    <GroupBox Header="Options" FontSize="20pt">
        <StackPanel>
            <RadioButton Template="{StaticResource newradio}"
                         HorizontalAlignment="Center" 
                         Content="1" />
            <RadioButton Template="{StaticResource newradio}"
                         HorizontalAlignment="Center"
                         Content="2"
                         IsChecked="True" />
            <RadioButton Template="{StaticResource newradio}"
                         HorizontalAlignment="Center"
                         Content="3" />
        </StackPanel>
    </GroupBox>
</Page>

   
    
    
    
    
    
     


Color animate based on Radio Button Click event

image_pdfimage_print


   
      
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Background="{x:Static SystemColors.WindowBrush}"
      Name="page">

    <Page.Resources>
        <Style TargetType="{x:Type RadioButton}">
            <Setter Property="Margin" Value="6" />
        </Style>
    </Page.Resources>

    <StackPanel HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Background="{DynamicResource 
                                {x:Static SystemColors.ControlBrushKey}}">

        <RadioButton Content="Red">
            <RadioButton.Triggers>
                <EventTrigger RoutedEvent="RadioButton.Checked">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                                Storyboard.TargetName="page"
                                Storyboard.TargetProperty="Background.Color"
                                To="Red" Duration="0:0:1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </RadioButton.Triggers>
        </RadioButton>

    </StackPanel>
</Page>

   
    
    
    
    
    
     


Radio Button Groups

image_pdfimage_print


   
      
<Window x:Class="ClassicControls.RadioButtonGroups"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="RadioButtonGroups" Height="300" Width="300">
    <StackPanel>
      <GroupBox Margin="5">
        <StackPanel>
          <RadioButton>Group 1</RadioButton>
          <RadioButton>Group 1</RadioButton>
          <RadioButton>Group 1</RadioButton>
          <RadioButton Margin="0,10,0,0" GroupName="Group2">Group 2</RadioButton>
        </StackPanel>
      </GroupBox>
      <GroupBox Margin="5">
        <StackPanel>
          <RadioButton>Group 3</RadioButton>
          <RadioButton>Group 3</RadioButton>
          <RadioButton>Group 3</RadioButton>
          <RadioButton Margin="0,10,0,0" GroupName="Group2">Group 2</RadioButton>
        </StackPanel>
      </GroupBox>
    </StackPanel>
</Window>

   
    
    
    
    
    
     


Set RadioButton to check state

image_pdfimage_print


   
      
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="FlowDocumentPage" Height="450" Width="500">
    <DockPanel>
        <Button Padding="20" Margin="40">
            <FlowDocumentReader>
                <FlowDocument FontSize="12" xml:space="preserve">
                    <Paragraph TextAlignment="Center" FontSize="18"><Bold>bold</Bold></Paragraph>
                    <Paragraph>Para<Italic>italic</Italic>HTML</Paragraph>
                    <Paragraph>aaa<Button>Push me</Button> 
                    <RadioButton IsChecked="True">Yes</RadioButton>
                    <RadioButton>No</RadioButton>
                    <RadioButton>Unsure</RadioButton>
                    </Paragraph>
                    <Paragraph><Bold>Lists:</Bold></Paragraph>
                    <List>
                        <ListItem><Paragraph>A</Paragraph></ListItem>
                        <ListItem><Paragraph>B</Paragraph></ListItem>
                        <ListItem><Paragraph>C<Ellipse Fill="Red" Width="20" Height="20"/></Paragraph></ListItem>
                        <ListItem><Paragraph>D<Rectangle Fill="Blue" Width="20" Height="20"></Rectangle></Paragraph></ListItem>
                    </List>
                </FlowDocument>
            </FlowDocumentReader>
        </Button>
    </DockPanel>
</Window>

   
    
    
    
    
    
     


Image RadioButton

image_pdfimage_print


   
 
<Window x:Class="ControlDemos.RadioButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ControlDemos" Height="600" Width="500">
    <Grid>
      <StackPanel>
        <RadioButton Click="HandleSelection" Name="r1">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" ></Image>
            <TextBlock FontSize="24" Height="35" Width="150">A</TextBlock>
          </StackPanel>
        </RadioButton>
        <RadioButton Click="HandleSelection" Name="r2">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" ></Image>
            <TextBlock FontSize="24" Height="35" Width="150">B</TextBlock>
          </StackPanel>
        </RadioButton>
        <RadioButton Click="HandleSelection" Name="r3">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" Height="200" Width="256"></Image>
            <TextBlock FontSize="24" Height="35" Width="150">C</TextBlock>
          </StackPanel>
        </RadioButton>
      </StackPanel>
  <Menu Name="menu1" />
</Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ControlDemos
{
    public partial class RadioButton : Window
    {

        public RadioButton()
        {
            InitializeComponent();
        }
        public void HandleSelection(Object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.RadioButton b = (sender as System.Windows.Controls.RadioButton);
            StackPanel d = (StackPanel)b.Content;
            TextBlock t = (TextBlock)d.Children[1];
            Console.WriteLine(t.Text);
        }
    }
}

   
     


RadioButton click event

image_pdfimage_print


   
 
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ProgBar.Window1"
    Title ="ProgressBar"
    Width="500">

  <Grid>
    <StackPanel Grid.Column="0" Grid.Row="2">
      <Label>Choose number of ProgressBar iterations.</Label>
      <RadioButton Content="One" Click="MakeOne"/>
      <RadioButton Content="Three" Click="MakeThree"/>
      <RadioButton Content="Five" Click="MakeFive"/>
      <RadioButton Content="Forever" Click="MakeForever"/>
      <RadioButton Content="Indeterminate" Click="MakeIndeterminate"/>
    </StackPanel>
  </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;



namespace ProgBar
{

    public partial class Window1 : Window
    {
        
        private void MakeOne(object sender, RoutedEventArgs e)
        {
           Console.WriteLine("E");
          } 

         private void MakeThree(object sender, RoutedEventArgs e)
         {
           Console.WriteLine("D");
         }
        
        private void MakeFive(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("c");
         }
 
         private void MakeForever(object sender, RoutedEventArgs e)
         {
           Console.WriteLine("B");
          
         }

         private void MakeIndeterminate(object sender, RoutedEventArgs e)
         {
             Console.WriteLine("A");
         }

     }
}