protected override void OnNavigatedTo(NavigationEventArgs e) { var parameter = e.Parameter as QuestionAndAnswer; DataContext = this; QuestionAndAnswer = parameter; }
private async void btLuu_ClickAsync(object sender, RoutedEventArgs e) { string ERR = ""; foreach (QuestionAndAnswer item in CreateQAList.listQA) { if (item.cau_hoi == txtCauHoi.Text) { ERR = "Câu hỏi bị trùng, vui lòng nhập câu hỏi khác"; } } if (txtCauHoi.Text == "") { ERR += "Vui lòng nhập câu hỏi\n"; } if (txtDapAn.Text == "") { ERR += "Vui lòng nhập đáp án\n"; } if (ERR != "") { MessageDialog thongbao = new MessageDialog("Lỗi:\n" + ERR); await thongbao.ShowAsync(); return; } QuestionAndAnswer QA = new QuestionAndAnswer(); int thu_tu = CreateQAList.listQA.Count() + 1; QA.thu_tu = thu_tu; QA.cau_hoi = "Câu số " + thu_tu + ": " + txtCauHoi.Text; QA.dap_an = "\n" + txtDapAn.Text; CreateQAList.listQA.Add(QA); CreateQAList.listQA.Reverse(); //TODO: save CreateQAList.listAdded to file //string path = @"C:\Users\Vinh"; string text = JsonConvert.SerializeObject(CreateQAList.listQA); //File.WriteAllText(Path.Combine(path), text); await WriteFile(text); MessageDialog thongbao1 = new MessageDialog("Đã lưu thành công!"); await thongbao1.ShowAsync(); }