<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);
}
}
}
|