我的Windows Phone 7应用程序中有一个表单,其中包含一些文本框和一个单选按钮。我想在单击重置按钮时重置文本框和单选按钮的值。我能够清除文本框但不知道如何清除单选按钮的值。请帮忙:
我的表格是:
<TextBox GotFocus="OnGotFocus" Canvas.Left="6" Canvas.Top="6" Height="74" Name="name" Text="*Name" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus1" Canvas.Left="6" Canvas.Top="66" Height="74" Name="age" Text="*Age" Width="453" BorderThickness="0" />
<TextBlock Canvas.Left="20" Canvas.Top="157" Height="44" Name="gen" Text="Gender" Foreground="Black" FontFamily="Verdana" FontSize="24" Width="134" />
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
<TextBox GotFocus="OnGotFocus2" Canvas.Left="6" Canvas.Top="267" Height="74" Name="sadd" Text="*Street Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus3" Canvas.Left="6" Canvas.Top="327" Height="74" Name="cadd" Text="*City Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus4" Canvas.Left="6" Canvas.Top="387" Height="74" Name="eadd" Text="*Email Address" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus5" Canvas.Left="6" Canvas.Top="447" Height="74" Name="phn" Text="*Phone" Width="453" BorderThickness="0"/>
<TextBox GotFocus="OnGotFocus6" Canvas.Left="6" Canvas.Top="507" Height="74" Name="zip" Text="*Zip Code" Width="453" BorderThickness="0"/>
点击重置按钮时重置的代码是:
private void reset_Click(object sender, RoutedEventArgs e)
{
name.Text = "";
age.Text = "";
sadd.Text = "";
cadd.Text = "";
eadd.Text = "";
phn.Text = "";
zip.Text = "";
}
请添加我应添加的代码以重置单选按钮
现在点击提交按钮,如果我想检查是否已选择男性或女性,我该怎么做。对于文本框,我正在执行以下代码:
private void submit_Click(object sender, RoutedEventArgs e)
{
if (name.Text == "")
{
MessageBox.Show("Please Enter the name");
name.Focus();
}
}
答案 0 :(得分:1)
有一个名为content的属性,它等同于文本框文本属性
这就是你要设置它的方式
male.IsChecked=false;
male.Content=String.Empty;
关于编辑。
为两个radiobuttons分配一个公共groupname属性。即
<RadioButton Canvas.Left="139" Canvas.Top="157" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Male" Height="71" Name="male" Width="154" />
<RadioButton Canvas.Left="139" Canvas.Top="207" FontStyle="Italic" GroupName="Gender" Foreground="Black" Content="Female" Height="71" Name="fem" Width="140" />
这使得每次在xaml中选择两个中的任何一个。
现在在代码中获取radiobutton的值应该是。
if(male.IsChecked==true)
{
string gender=male.Content.ToString();
}
else if(female.isChecked==true)
{
string gender=female.Content.ToString();
}
else //none of them is selected.
{
MessageBox.Show("Text");
}