void AddAnswer(object sender, AnswersModel answer) { StackPanel panel = ((sender as Button).Parent as StackPanel); Viewbox labelBox = DynamicElements.CreateViewBoxLabel("Ответ №" + (answerCount + 1), 0); labelBox.MaxHeight = 40; panel.Children.Add(labelBox); Viewbox box = new Viewbox(); box.MaxHeight = 60; CheckBox chbox = DynamicElements.CreateCheckBox(answer.Rightness); chbox.Name = "answer" + answerCount; chbox.ToolTip = "Правильность"; box.Child = chbox; TextBox txtBox = new TextBox(); txtBox.MinWidth = 150; txtBox.MaxWidth = 150; txtBox.Text = answer.Text; chbox.Content = txtBox; panel.Children.Add(box); panel.Children.Remove(sender as Button); panel.Children.Add(sender as Button); answerCount++; }
public void SetMainData(TestsModel test) { int questCount = 0; foreach (QuestionsModel quest in test.Questions) { int count = 0; Grid grid = DynamicElements.CreateGrid(5, quest.Answers.Count + 3, GridUnitType.Star, GridUnitType.Star); RichTextBox rtb = new RichTextBox(); rtb.Name = "rtb_Question" + quest.Id; DynamicElements.SetRowColumnProperties(rtb, count, 1, 4, 2); Viewbox number = DynamicElements.CreateViewBoxLabel((questCount + 1) + ".", 0); DynamicElements.SetRowColumnProperties(number, count, 0, 1, 1); grid.Children.Add(number); count += 3; rtb.AppendText(quest.Text); rtb.FontSize = fontSize; grid.Children.Add(rtb); foreach (AnswersModel answer in quest.Answers) { Border bord = new Border(); bord.Margin = new Thickness(1, 3, 1, 1); bord.MaxHeight = 100; if (answer.UserChoice == true && answer.Rightness == true) { bord.Background = this.FindResource("Green") as Brush; } else if (answer.UserChoice == true) { bord.Background = Brushes.PaleVioletRed; } else if (answer.Rightness == true) { bord.Background = Brushes.LightGreen; } Viewbox vb = new Viewbox(); vb.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; CheckBox cb = DynamicElements.CreateCheckBox(answer.UserChoice); vb.Child = cb; cb.Content = answer.Text; bord.Child = vb; DynamicElements.SetRowColumnProperties(bord, count, 1, 3, 1); count++; grid.Children.Add(bord); } panel.Children.Add(grid); questCount++; } }
public void SetAnswers(List <AnswersModel> answers) { int count = grid.RowDefinitions.Count; int i = 1; foreach (AnswersModel answer in answers) { AddRow(grid); Viewbox vb = new Viewbox(); DynamicElements.SetRowColumnProperties(vb, count, 0, grid.ColumnDefinitions.Count, 1); CheckBox cb = DynamicElements.CreateCheckBox(answer.UserChoice); cb.Name = "Checkbox" + i; i++; cb.Tag = answer.Id; cb.Content = answer.Text; vb.Child = cb; vb.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; grid.Children.Add(vb); count++; } }