Image RadioButton : RadioButton « Windows Presentation Foundation « C# / CSharp Tutorial






<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);
        }
    }
}
WPF Image Radio Button








24.21.RadioButton
24.21.1.Checked RadioButtonChecked RadioButton
24.21.2.Use StackPanel to Hold RadioButtonsUse StackPanel to Hold RadioButtons
24.21.3.Circled Radio ButtonsCircled Radio Buttons
24.21.4.Color animate based on Radio Button Click eventColor animate based on Radio Button Click event
24.21.5.Radio Button GroupsRadio Button Groups
24.21.6.Set RadioButton to check stateSet RadioButton to check state
24.21.7.Image RadioButtonImage RadioButton
24.21.8.Add checked event listener to RadioButton
24.21.9.Assign value to RadioButton tag