public SendNewThreadContentDialogViewModel(CancellationTokenSource cts, int forumId, Action <int, int, string> beforeUpload, Action <string> insertFileCodeIntoContentTextBox, Action <int> afterUpload, Action <string> sentFailded, Action <string> sentSuccess) { _beforeUpload = beforeUpload; _insertFileCodeIntoContentTextBox = insertFileCodeIntoContentTextBox; _afterUpload = afterUpload; _sentSuccess = sentSuccess; _sentFailded = sentFailded; AddAttachFilesCommand = new DelegateCommand(); AddAttachFilesCommand.ExecuteAction = async(p) => { var data = await SendService.UploadFileAsync(cts, _beforeUpload, _afterUpload); if (data[0] != null && data[0].Count > 0) { _fileNameList.AddRange(data[0]); } if (data[1] != null && data[1].Count > 0) { _fileCodeList.AddRange(data[1]); } if (_fileCodeList.Count > 0) { string fileCodes = string.Join("\r\n", _fileCodeList); _insertFileCodeIntoContentTextBox($"\r\n{fileCodes}\r\n"); _fileCodeList.Clear(); } }; SendCommand = new DelegateCommand(); SendCommand.ExecuteAction = async(p) => { if (string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(Content)) { _sentFailded("请将标题及内容填写完整!"); return; } bool flag = await SendService.SendNewThreadAsync(cts, Title, Content, _fileNameList, forumId); if (flag) { _fileNameList.Clear(); Title = string.Empty; Content = string.Empty; // 提示发贴成功 if (_sentSuccess != null) { _sentSuccess(Title); } } else { // 提示发贴不成功 if (_sentFailded != null) { _sentFailded("对不起,发布请求失败,请稍后再试!"); } } }; }