0

I am implementing online tests on the WPF platform, database queries are made through ado.net, the question block is output through itemcontrol, itemsource which is taken from the database, answer options are presented as radio buttons. Checking the correctness of the question is done by running the elements through the loop, but in the Items property of the itemcontrol, the loop does not see the radio buttons in the itemcontrol Let's get to the point. How to make itemcontrol see elements inside itself?

<ItemsControl Name="QuestionControl" 
                      ItemsSource="{Binding}"
                      VerticalAlignment="Top"
                      Margin="10">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Name ="SpQuestion">
                        <TextBlock Text="{Binding Path=Question.QuestionName}"
                                   Tag="{Binding Path=Question.AnswerName}"
                                   Name="TbRight"
                                   FontSize="22"
                                   TextWrapping="Wrap"/>
                        <StackPanel Margin="10">
                            <RadioButton Content="{Binding Path=VariantsOne}" 
                                         Background="Transparent"
                                         />
                            <RadioButton Background="Transparent"
                                         Content="{Binding Path=VariantsThree}"
                                         />
                            <RadioButton Background="Transparent"
                                         
                                         Content="{Binding Path=VariantsTwo}"/>
                            <RadioButton Background="Transparent"
                                         Content="{Binding Path=VariantsFour}"
                                         />
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
  • https://stackoverflow.com/questions/883246/mvvm-radiobuttons – ASh Mar 09 '22 at 17:57
  • Check the collection instead. ItemsControl only interacts with your questions collection. And look into MvvM. It will save you a lot of this trouble. – XAMlMAX Mar 09 '22 at 18:42

0 Answers0