代码:
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="370*" />
<ColumnDefinition Width="86*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="2" Height="79" HorizontalAlignment="Left" Margin="66,56,0,0" Name="textBlock1" Text="请选择你喜欢的手机的品牌:" VerticalAlignment="Top" Width="343" />
<RadioButton Content="A、苹果" Height="91" HorizontalAlignment="Left" Margin="96,122,0,0" Name="radioButton1" VerticalAlignment="Top" Width="224" Checked="radioButton1_Checked" GroupName="phone" />
<RadioButton Content="B、三星" Height="73" HorizontalAlignment="Left" Margin="96,204,0,0" Name="radioButton2" VerticalAlignment="Top" Width="202" Checked="radioButton2_Checked" GroupName="phone" />
<RadioButton Content="C、HTC" Height="73" HorizontalAlignment="Left" Margin="96,283,0,0" Name="radioButton3" VerticalAlignment="Top" Width="202" Checked="radioButton3_Checked" GroupName="phone" />
<TextBlock Height="77" HorizontalAlignment="Left" Margin="50,417,0,0" Name="textBlock2" Text="您的选择是:" VerticalAlignment="Top" Width="149" />
<TextBlock Height="59" HorizontalAlignment="Left" Margin="183,413,0,0" Name="textBlock3" Text="" VerticalAlignment="Top" Width="177" />
</Grid>
//当选择的时候自动调用的方法
private void radioButton1_Checked(object sender, RoutedEventArgs e)
{
//如果苹果被选中,在答案中显示苹果选项
if (radioButton1.IsChecked == true) {
textBlock3.Text = radioButton1.Content.ToString();
}
}
private void radioButton2_Checked(object sender, RoutedEventArgs e)
{
//如果三星被选中,在答案中显示三星选项
if (radioButton2.IsChecked == true)
{
textBlock3.Text = radioButton2.Content.ToString();
}
}
private void radioButton3_Checked(object sender, RoutedEventArgs e)
{
//如果HTC被选中,在答案中显示HTC选项
if (radioButton3.IsChecked == true)
{
textBlock3.Text = radioButton3.Content.ToString();
}
}