public SendThreadQuickReplyControlViewModel(CancellationTokenSource cts, int threadId, Action <int, int, string> beforeUpload, Action <string> insertFileCodeIntoContentTextBox, Action <int> afterUpload, Action <string> sentFailded, Action <string> sentSuccess) { _threadId = threadId; _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(); } }; AddInkImageCommand = new DelegateCommand(); AddInkImageCommand.ExecuteAction = (p) => { var frame = (Frame)Window.Current.Content; var mainPage = (MainPage)frame.Content; mainPage.OpenInkPanel(); mainPage.UploadInkContentDelegate = (data) => { 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(); } }; mainPage.PostInkContentDelegate = async(data) => { 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(); } bool flag = await SendService.SendThreadReplyAsync(cts, $"{data[1][0]}", _fileNameList, _threadId); if (flag) { _fileNameList.Clear(); Content = string.Empty; // 提示发贴成功 _sentSuccess?.Invoke(string.Empty); } else { // 提示发贴不成功 _sentFailded?.Invoke("对不起,发布请求失败,请稍后再试!"); } }; }; SendCommand = new DelegateCommand(); SendCommand.ExecuteAction = async(p) => { if (string.IsNullOrEmpty(Content)) { _sentFailded("请填写内容!"); return; } bool flag = await SendService.SendThreadReplyAsync(cts, Content, _fileNameList, _threadId); if (flag) { _fileNameList.Clear(); Content = string.Empty; // 提示发贴成功 _sentSuccess?.Invoke(string.Empty); } else { // 提示发贴不成功 _sentFailded?.Invoke("对不起,发布请求失败,请稍后再试!"); } }; }