Windows 8.1应用程序c# XAML帮助:显示消息,如果没有选择单选按钮
本文关键字:消息 如果 单选按钮 有选择 显示 应用程序 帮助 XAML Windows | 更新日期: 2023-09-27 18:05:09
我正在尝试编写我的essurvey应用程序。我有一个单选按钮列表。下面是SurveyPage1.xaml:
的代码<StackPanel Grid.Row="1" Margin="-10,10,10,-10">
<TextBlock Text="PARLIAMENT VISITOR CENTRE SURVEY" FontWeight="Bold" FontSize="48" Margin="100,0,0,0" VerticalAlignment="Top"/>
<TextBlock Text="1. How would you describe your overall visit experience?" Margin="100,100,0,0" FontSize="18"/>
<RadioButton Name="radioExcellent" Content="Excellent" Margin="100,10,0,0" FontSize="12"/>
<RadioButton Name="radioGood" Content="Good" Margin="100,10,0,0" FontSize="12"/>
<RadioButton Name="radioAverage" Content="Average" Margin="100,10,0,0" FontSize="12"/>
<RadioButton Name="radioPoor" Content="Poor" Margin="100,10,0,0" FontSize="12"/>
</StackPanel>
<Button Name="nextButton1" Content="Next" HorizontalAlignment="Left" Margin="1250,525,0,0" Grid.Row="1" VerticalAlignment="Center" Background="#FFED2E38" Click="Button_S1_S2"/>
和我的surveypage1 . example .cs:
private void Button_S1_S2(object sender, RoutedEventArgs e)
{
if (this.Frame != null)
{
this.Frame.Navigate(typeof(SurveyPage2));
}
}
我想做的是,如果没有单选按钮被选中,它将不会继续到下一页(单击nextButton1将显示一个错误,说"请输入一个选项。")
有人能帮我一下吗?感谢!您可以在nextButton1点击处理程序中检查所有RadioButton
的IsChecked
属性:
private async void Button_S1_S2(object sender, RoutedEventArgs e)
{
if (radioExcellent.IsChecked != true && radioGood.IsChecked != true && radioAverage.IsChecked != true && radioPoor.IsChecked != true)
{
MessageDialog md = new MessageDialog("Please rate the content before proceeding!");
await md.ShowAsync();
}
else
{
if (this.Frame != null)
{
this.Frame.Navigate(typeof(SurveyPage2));
}
}
}
在下一个按钮的click事件处理程序中,检查是否设置了某些单选按钮