public QuestionsModel GetQuestion(out int id) { QuestionsModel question = null; bool emptyAnswer = false; RichTextBox rtb = LogicalTreeHelper.FindLogicalNode(this, "rtb_Question") as RichTextBox; string content = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd).Text; id = Convert.ToInt32(rtb.Tag); question = new QuestionsModel(id, 0, content);//, null for (int i = 0; i < answerCount; i++) { AnswersModel answer = null; CheckBox chbox = LogicalTreeHelper.FindLogicalNode(this, "answer" + i) as CheckBox; bool? right = chbox.IsChecked; string text = (chbox.Content as TextBox).Text.ToString(); if (string.IsNullOrEmpty(text)) { emptyAnswer = true; } answer = new AnswersModel(i, id, text, Convert.ToBoolean(right)); //null question.Answers.Add(answer); } if (string.IsNullOrEmpty(content) || content == "\r\n" || emptyAnswer) { MessageBox.Show("Вопрос и ответы не должны быть пустыми."); sp_Questions.IsEnabled = false; btn_Complete.IsEnabled = false; return(null); } else { return(question); } }
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++; }