我正在创建一个WPF应用程序,该应用程序允许用户进行测验,然后提交答案。我有一个ListView,每行显示2个标签和4个RadioButton。第一个标签是用于项目编号。第二个标签是当前项目的问题。4 radiobutton是用户可以选择的选择。我的listView中的项目是我创建的命名为"问题"的类中的。它具有7个属性,即:数字,问题,选择1,Choice2,choice3,choice4和recript_answer。ListView中仅显示" recript_answer"属性。如果我单击"提交"按钮,我想知道列表视图中每个行项目的radiobutton均可让我知道他们是否正确回答了每个项目,并为他们提供了有关其正确数量的分数。请建议。
下面是我的xaml
<ListView x:Name="list_question" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding number}" HorizontalAlignment="Left" VerticalAlignment="Top"></Label>
<Label Content="{Binding problem}" HorizontalAlignment="Left" HorizontalContentAlignment="Left" VerticalAlignment="Top"></Label>
</StackPanel>
<RadioButton Grid.Row="1" Content="{Binding choice1}"></RadioButton>
<RadioButton Grid.Row="1" Grid.Column="1" Content="{Binding choice3}"></RadioButton>
<RadioButton Grid.Row="2" Content="{Binding choice2}"></RadioButton>
<RadioButton Grid.Row="2" Grid.Column="1" Content="{Binding choice4}"></RadioButton>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我的按钮单击事件处理程序
private void btn_submit_Click(object sender, RoutedEventArgs e)
{
foreach (var item in list_question.Items)
{
}
}
如果您使用的是无线电按钮选择4个选择,则首先需要为所有选项放置相同名称,然后将帮助您获得选择的选择以及允许结束用户只选择一个选项。