Good day!
I have a form with a stack panel of questions. Each question has a number of answers which look like a list of radiobuttons.
I make my xaml dynamically:
<StackPanel x:Name="spQuestions" Orientation="Vertical" Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="3" HorizontalAlignment="Left">
</StackPanel>
foreach (QuestionDTO question in questions)
{
StackPanel newsp = new StackPanel();
newsp.Orientation = Orientation.Vertical;
TextBlock textBlock = new TextBlock();
textBlock.Text = question.Text;
newsp.Children.Add(textBlock);
RadGridView gridView = new RadGridView();
gridView.Name = "grAnsw" + question.Id.ToString();
gridView.ItemsSource = question.Answers;
gridView.AutoGenerateColumns = false;
gridView.IsReadOnly = true;
GridViewRadioButtonColumn col = new GridViewRadioButtonColumn();
gridView.Columns.Add(col);
newsp.Children.Add(gridView);
spQuestions.Children.Add(newsp);
}
where
public class GridViewRadioButtonColumn : GridViewDataColumn
{
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
var radioButton = cell.Content as RadioButton;
if (radioButton == null)
{
radioButton = new RadioButton();
radioButton.SetBinding(RadioButton.ContentProperty, new Binding("Text")
{
Source = dataItem
});
cell.Content = radioButton;
}
return radioButton;
}
}
In the result I have the page which I wanted, but all radio buttons look like they are in the same list. So I can check only one radiobutton on the page, but I want to check one radiobutton in one question, but there are a number of questions on the page =(
How can I make the page see that there are different lists of radiobuttons for each question?
Thank you.
I have a form with a stack panel of questions. Each question has a number of answers which look like a list of radiobuttons.
I make my xaml dynamically:
<StackPanel x:Name="spQuestions" Orientation="Vertical" Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="3" HorizontalAlignment="Left">
</StackPanel>
foreach (QuestionDTO question in questions)
{
StackPanel newsp = new StackPanel();
newsp.Orientation = Orientation.Vertical;
TextBlock textBlock = new TextBlock();
textBlock.Text = question.Text;
newsp.Children.Add(textBlock);
RadGridView gridView = new RadGridView();
gridView.Name = "grAnsw" + question.Id.ToString();
gridView.ItemsSource = question.Answers;
gridView.AutoGenerateColumns = false;
gridView.IsReadOnly = true;
GridViewRadioButtonColumn col = new GridViewRadioButtonColumn();
gridView.Columns.Add(col);
newsp.Children.Add(gridView);
spQuestions.Children.Add(newsp);
}
where
public class GridViewRadioButtonColumn : GridViewDataColumn
{
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
var radioButton = cell.Content as RadioButton;
if (radioButton == null)
{
radioButton = new RadioButton();
radioButton.SetBinding(RadioButton.ContentProperty, new Binding("Text")
{
Source = dataItem
});
cell.Content = radioButton;
}
return radioButton;
}
}
In the result I have the page which I wanted, but all radio buttons look like they are in the same list. So I can check only one radiobutton on the page, but I want to check one radiobutton in one question, but there are a number of questions on the page =(
How can I make the page see that there are different lists of radiobuttons for each question?
Thank you.