Fork me on GitHub

RadioButton

 

RadioButton中,唯一要说的说是GroupName,当有这个属性时,可以指定同一个容器中的组,如果没有这个参属性,默认当所有RadioButton都以这个容器为一组。

XAML代码:
<TextBlock Margin="10,10,3,73.778" Grid.Column="0" Grid.Row="0" FontSize="24"

        >RadioButton</TextBlock>

<DockPanel Margin="10,57.56,3,38.338" Grid.Column="0"/>     

<DockPanel Margin="10,46.197,3,24.261" Grid.Column="0">

    <TextBlock Name="txtb" FontSize="12">Click a radio button.</TextBlock>

<StackPanel>     

    <RadioButton Name="rb1" Checked="WriteText2">Yes</RadioButton>

    <RadioButton Name="rb2" Checked="WriteText2">No</RadioButton>

    <RadioButton Name="rb3" Checked="WriteText2">No opinion</RadioButton>

</StackPanel>

</DockPanel>

<DockPanel Margin="10,0,3,0" Grid.Column="0" VerticalAlignment="Bottom" Height="63.84">

<TextBlock FontSize="12">Choose color and number.</TextBlock>

<StackPanel>

    <RadioButton GroupName="colorgrp">Red</RadioButton>

    <RadioButton GroupName="colorgrp">Blue</RadioButton>

    <RadioButton GroupName="numgrp">1</RadioButton>

    <RadioButton GroupName="numgrp">2</RadioButton>

</StackPanel>

</DockPanel>

 CS代码:

         void WriteText2(object sender, RoutedEventArgs e)

      {

               RadioButton li = (sender as RadioButton);

                txtb.Text = "You clicked " + li.Content.ToString() + ".";

        }  

posted @ 2007-04-23 12:38  桂素伟  阅读(1322)  评论(1编辑  收藏  举报