private void QuesItem_SelectionChanged(object sender, SelectionChangedEventArgs e) //显示问题详情与回答 { if (QuesItem.SelectedIndex < 0) { return; } CurrentQuesIndex = QuesItem.SelectedIndex; CurrentQuestion = QuestionList[QuesItem.SelectedIndex]; this.ques_info.DataContext = QuestionList[QuesItem.SelectedIndex]; this.DisplayAnswers = new List <DisplayAnswer>(); foreach (Answer answer in QuestionList[QuesItem.SelectedIndex].Answers) { DisplayAnswer displayAnswer = new DisplayAnswer(); displayAnswer.convert(answer); if (QuestionList[QuesItem.SelectedIndex].UserId == User.UserId && QuestionList[QuesItem.SelectedIndex].Solved == false) { displayAnswer.ShowAdoptBtn = true; } else { displayAnswer.ShowAdoptBtn = false; } if (answer.UserId == User.UserId) { displayAnswer.IsMyAnswer = true; } else { displayAnswer.IsMyAnswer = false; } this.DisplayAnswers.Add(displayAnswer); } this.AnsItem.ItemsSource = this.DisplayAnswers; }
private void Answer_Click(object sender, RoutedEventArgs e) //回答 { if (CurrentQuestion == null) { return; } else if (User.UserId == null) { tipWindow warning = new tipWindow("请先登录"); warning.ShowDialog(); return; } else if (CurrentQuestion.UserId == User.UserId) { tipWindow warning = new tipWindow("不能回答自己的提问"); warning.ShowDialog(); return; } else if (AnswerContent.Text == null || AnswerContent.Text == "") { tipWindow warning = new tipWindow("回答不能为空"); warning.ShowDialog(); return; } else if (DisplayAnswers.Count >= 15) { tipWindow warning = new tipWindow("回答已满"); warning.ShowDialog(); return; } bool success = User.Answer(AnswerContent.Text, CurrentQuestion.QuestionId); if (success) { Answer newAnswer = new Answer(AnswerContent.Text, DateTime.Now, User.UserId, false, -1, 0); QuestionList[CurrentQuesIndex].Answers.Add(newAnswer); DisplayAnswer disp = new DisplayAnswer(); disp.convert(newAnswer); disp.ShowAdoptBtn = false; disp.IsMyAnswer = true; this.DisplayAnswers.Add(disp); AnswerContent.Text = ""; this.AnsItem.ItemsSource = null; this.AnsItem.ItemsSource = this.DisplayAnswers; } else { tipWindow warning = new tipWindow("未知错误"); warning.ShowDialog(); return; } }