AnnotationContentViewModel.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFPage;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.AnnotEvent;
  7. using ComPDFKitViewer.PdfViewer;
  8. using DryIoc;
  9. using ImTools;
  10. using Microsoft.Office.Interop.Excel;
  11. using Microsoft.Office.Interop.PowerPoint;
  12. using Microsoft.Office.Interop.Word;
  13. using PDF_Office.CustomControl;
  14. using PDF_Office.DataConvert;
  15. using PDF_Office.Helper;
  16. using PDF_Office.Model;
  17. using PDF_Office.Model.BOTA;
  18. using PDF_Office.Views.BOTA;
  19. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  20. using Prism.Commands;
  21. using Prism.Mvvm;
  22. using Prism.Regions;
  23. using Prism.Services.Dialogs;
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Collections.ObjectModel;
  27. using System.ComponentModel;
  28. using System.Configuration;
  29. using System.Drawing;
  30. using System.Linq;
  31. using System.Text;
  32. using System.Threading.Tasks;
  33. using System.Windows;
  34. using System.Windows.Annotations;
  35. using System.Windows.Annotations.Storage;
  36. using System.Windows.Controls;
  37. using System.Windows.Data;
  38. using System.Windows.Documents;
  39. using System.Windows.Forms;
  40. using System.Windows.Markup;
  41. using System.Windows.Media;
  42. using System.Windows.Media.Imaging;
  43. using System.Windows.Shapes;
  44. using static Dropbox.Api.Files.SearchMatchType;
  45. using static Dropbox.Api.TeamLog.SpaceCapsType;
  46. using static System.Net.Mime.MediaTypeNames;
  47. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  48. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
  49. using Border = System.Windows.Controls.Border;
  50. using ListBox = System.Windows.Controls.ListBox;
  51. using Task = System.Threading.Tasks.Task;
  52. using TextBox = System.Windows.Controls.TextBox;
  53. using Winform = System.Windows.Forms;
  54. namespace PDF_Office.ViewModels.BOTA
  55. {
  56. public class AnnotationContentViewModel : BindableBase, INavigationAware
  57. {
  58. private ListBox listBox;
  59. private IRegionManager region;
  60. private IDialogService dialogs;
  61. private Visibility isEmptyPanelVisibility = Visibility.Visible;
  62. public ViewContentViewModel ViewContentViewModel { get; set; }
  63. public CPDFViewer PdfViewer { get; set; }
  64. public Visibility IsEmptyPanelVisibility
  65. {
  66. get { return isEmptyPanelVisibility; }
  67. set
  68. {
  69. SetProperty(ref isEmptyPanelVisibility, value);
  70. }
  71. }
  72. private ObservableCollection<AnnotationHandlerEventArgs> currentAnnotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  73. public ObservableCollection<AnnotationHandlerEventArgs> CurrentAnnotationArgs { get => currentAnnotationArgs; set => currentAnnotationArgs = value; }
  74. private AnnotationSortOrder annotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  75. public AnnotationSortOrder AnnotationSortOrder
  76. {
  77. get { return annotationSortOrder; }
  78. set { annotationSortOrder = value; }
  79. }
  80. private ObservableCollection<AnnotationHandlerEventArgs> annotationListItems;
  81. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems
  82. {
  83. get { return annotationListItems; }
  84. set
  85. {
  86. SetProperty(ref annotationListItems, value);
  87. }
  88. }
  89. private List<string> colors = new List<string>();
  90. private List<string> authors = new List<string>();
  91. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  92. public DelegateCommand<object> LoadedCommand { get; set; }
  93. public DelegateCommand<object> ListBoxItemPreviewMouseLeftButtonDown { get; set; }
  94. public DelegateCommand<object> AddNotesCommand { get; set; }
  95. public DelegateCommand<object> ScreenCommand { get; set; }
  96. public DelegateCommand<object> ExportCommentsCommand { get; set; }
  97. public DelegateCommand<object> ImportCommentsCommand { get; set; }
  98. public DelegateCommand<object> DeleteCommand { get; set; }
  99. public DelegateCommand DeleteAllCommand { get; set; }
  100. public DelegateCommand PageSortCommand { get; set; }
  101. public DelegateCommand TimeAscendingCommand { get; set; }
  102. public DelegateCommand TimeDescendingCommand { get; set; }
  103. public AnnotationContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  104. {
  105. region = regionManager;
  106. dialogs = dialogService;
  107. LoadedCommand = new DelegateCommand<object>(Loaded);
  108. ListBoxItemPreviewMouseLeftButtonDown = new DelegateCommand<object>(ListBoxItem_PreviewMouseLeftButtonDown);
  109. AddNotesCommand = new DelegateCommand<object>(AddNotesEvent);
  110. ScreenCommand = new DelegateCommand<object>(ScreenEvent);
  111. ExportCommentsCommand = new DelegateCommand<object>(ExportCommentsEvent);
  112. ImportCommentsCommand = new DelegateCommand<object>(ImportCommentsEvent);
  113. DeleteCommand = new DelegateCommand<object>(DelegateEvent);
  114. DeleteAllCommand = new DelegateCommand(DeleteAllEvent);
  115. PageSortCommand = new DelegateCommand(PageSortEvent);
  116. TimeAscendingCommand = new DelegateCommand(TimeAscendingEvent);
  117. TimeDescendingCommand = new DelegateCommand(TimeDescendingEvent);
  118. }
  119. /// <summary>
  120. /// 导入注释
  121. /// </summary>
  122. /// <param name="obj"></param>
  123. private async void ImportCommentsEvent(object obj)
  124. {
  125. Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  126. dlg.Filter = "PDF|*.xfdf";
  127. dlg.DefaultExt = ".xfdf";
  128. if (dlg.ShowDialog() == true)
  129. {
  130. string fileName = dlg.FileName;
  131. await Task.Delay(5);
  132. var result = PdfViewer.ImportAnnotationFromXFDFPath(fileName);
  133. if (result == false)
  134. {
  135. //MessageBoxEx.Show("导入失败", "", Winform.MessageBoxButtons.OK, Winform.MessageBoxIcon.Error);
  136. AlertsMessage alertsMessage = new AlertsMessage();
  137. alertsMessage.Show("提示", "导入失败!", "OK");
  138. return;
  139. }
  140. PdfViewer.ReloadVisibleAnnots();
  141. //提取出来的注释文件 时间为空 则显示未系统当前时间
  142. CurrentAnnotationArgs = GetDocumentAnnotionList();
  143. AnnotationListItems.Clear();
  144. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  145. await Task.Delay(5);
  146. RefreshAnnotationListItems(null);
  147. PdfViewer.UndoManager.CanSave = true;
  148. }
  149. }
  150. /// <summary>
  151. /// 时间倒序
  152. /// </summary>
  153. private void TimeDescendingEvent()
  154. {
  155. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  156. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  157. v.GroupDescriptions.Clear();
  158. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  159. v.SortDescriptions.Clear();
  160. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Descending));
  161. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Descending));
  162. AnnotationSortOrder = AnnotationSortOrder.TimeDescending;
  163. }
  164. /// <summary>
  165. /// 时间正序
  166. /// </summary>
  167. private void TimeAscendingEvent()
  168. {
  169. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  170. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  171. v.GroupDescriptions.Clear();
  172. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  173. v.SortDescriptions.Clear();
  174. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Ascending));
  175. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  176. AnnotationSortOrder = AnnotationSortOrder.TimeAscending;
  177. }
  178. /// <summary>
  179. /// 页面排序
  180. /// </summary>
  181. private void PageSortEvent()
  182. {
  183. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  184. v.GroupDescriptions.Clear();
  185. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.PageIndex)));
  186. v.SortDescriptions.Clear();
  187. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  188. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  189. AnnotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  190. }
  191. /// <summary>
  192. /// 删除所有注释
  193. /// </summary>
  194. private void DeleteAllEvent()
  195. {
  196. //调用集中删除的接口 方便一次性undo
  197. Dictionary<int, List<int>> deleteLists = new Dictionary<int, List<int>>();
  198. for (int i = 0; i < AnnotationListItems.Count; i++)
  199. {
  200. AnnotationHandlerEventArgs item = AnnotationListItems[i] as AnnotationHandlerEventArgs;
  201. if (!deleteLists.ContainsKey(item.PageIndex))
  202. {
  203. deleteLists.Add(item.PageIndex, new List<int>() { item.AnnotIndex });
  204. }
  205. else
  206. {
  207. var pagelist = deleteLists[item.PageIndex];
  208. pagelist.Add(item.AnnotIndex);
  209. }
  210. }
  211. PdfViewer.RemovePageAnnot(deleteLists);
  212. AnnotationListItems.Clear();
  213. CurrentAnnotationArgs.Clear();
  214. PdfViewer.UndoManager.CanSave = true;
  215. }
  216. /// <summary>
  217. /// 删除注释,单个/多个
  218. /// </summary>
  219. /// <param name="obj"></param>
  220. private void DelegateEvent(object obj)
  221. {
  222. if (obj is AnnotationHandlerEventArgs annotation)
  223. {
  224. if (annotation != null)
  225. {
  226. var result = PdfViewer.RemovePageAnnot(annotation.PageIndex, annotation.AnnotIndex);
  227. if (result)
  228. {
  229. AnnotationListItems.Remove(annotation);
  230. var annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
  231. CurrentAnnotationArgs.Remove(annotation1);
  232. //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
  233. UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
  234. PdfViewer.UndoManager.CanSave = true;
  235. }
  236. }
  237. }
  238. }
  239. /// <summary>
  240. /// 删除之后,更新
  241. /// </summary>
  242. /// <param name="pageIndex"></param>
  243. /// <param name="annoteIndex"></param>
  244. private void UpdateAnnotListAfterDelete(int pageIndex, int annoteIndex)
  245. {
  246. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  247. for (int j = 0; j < items.Count; j++)//用修改赋值的方式 可以解决删除后表头折叠的问题
  248. {
  249. if (items[j].AnnotIndex >= annoteIndex)//只需要更新比删除元素索引大的注释
  250. {
  251. for (int k = 0; k < AnnotationListItems.Count; k++)
  252. {
  253. //相当于将后面的索引-1
  254. if (AnnotationListItems[k].PageIndex == pageIndex &&
  255. AnnotationListItems[k].AnnotIndex == (items[j].AnnotIndex + 1) &&
  256. string.Equals(AnnotationListItems[k].MarkupContent, items[j].MarkupContent) &&
  257. string.Equals(AnnotationListItems[k].Content, items[j].Content) &&
  258. string.Equals(AnnotationListItems[k].CreateTime, items[j].CreateTime) &&
  259. string.Equals(AnnotationListItems[k].Author, items[j].Author)
  260. )
  261. {
  262. AnnotationListItems[k].AnnotHandlerEventArgs = items[j];
  263. AnnotationListItems[k].PageIndex = items[j].PageIndex;
  264. AnnotationListItems[k].AnnotIndex = items[j].AnnotIndex;
  265. AnnotationListItems[k].EventType = items[j].EventType;
  266. AnnotationListItems[k].CreateTime = items[j].CreateTime;
  267. AnnotationListItems[k].UpdateTime = items[j].UpdateTime;
  268. if (items[j].EventType == AnnotArgsType.AnnotFreehand)
  269. {
  270. WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, items[j].PageIndex, items[j].AnnotIndex);
  271. AnnotationListItems[k].WriteableBitmap = bitmap;
  272. }
  273. AnnotationListItems[k].Content = items[j].Content;
  274. AnnotationListItems[k].MarkupContent = items[j].MarkupContent;
  275. AnnotationListItems[k].Author = items[j].Author;
  276. AnnotationListItems[k].Locked = items[j].Locked;
  277. AnnotationListItems[k].ReadOnly = items[j].ReadOnly;
  278. AnnotationListItems[k].FormField = items[j].FormField;
  279. AnnotationListItems[k].Document = PdfViewer.Document;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. /// <summary>
  286. /// 导出注释
  287. /// </summary>
  288. /// <param name="obj"></param>
  289. private void ExportCommentsEvent(object obj)
  290. {
  291. if (ViewContentViewModel.CanSave)
  292. {
  293. ViewContentViewModel.SaveFile.Execute();
  294. }
  295. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  296. dlg.Filter = "PDF|*.xfdf";
  297. dlg.DefaultExt = ".xfdf";
  298. dlg.FileName = PdfViewer.Document.FileName;
  299. if (dlg.ShowDialog() == true)
  300. {
  301. string fileName = dlg.FileName;
  302. var result = PdfViewer.ExportAnnotationToXFDFPath(fileName);
  303. if (result)
  304. {
  305. //MessageBoxEx.Show("导出成功", "", Winform.MessageBoxButtons.OK);
  306. AlertsMessage alertsMessage = new AlertsMessage();
  307. alertsMessage.Show("提示", "导出成功!", "OK");
  308. }
  309. else
  310. {
  311. AlertsMessage alertsMessage = new AlertsMessage();
  312. alertsMessage.Show("提示", "导出失败!", "OK");
  313. //MessageBoxEx.Show("导出失败", "", Winform.MessageBoxButtons.OK, Winform.MessageBoxIcon.Error);
  314. }
  315. }
  316. }
  317. /// <summary>
  318. /// 筛选注释
  319. /// </summary>
  320. /// <param name="obj"></param>
  321. private void ScreenEvent(object obj)
  322. {
  323. if (obj is System.Windows.Controls.Button button)
  324. {
  325. DialogParameters value = new DialogParameters();
  326. value.Add(ParameterNames.AnnotationList, CurrentAnnotationArgs);
  327. value.Add(ParameterNames.AnnotArgsTypes, annotArgsTypes);
  328. value.Add(ParameterNames.AnnotationColors, colors);
  329. value.Add(ParameterNames.AnnotationAuthor, authors);
  330. dialogs.ShowDialog(DialogNames.ScreenAnnotationDialog, value, e =>
  331. {
  332. if (e.Result == ButtonResult.OK && e.Parameters != null)
  333. {
  334. bool cleanState = false;
  335. if (e.Parameters.ContainsKey(ParameterNames.AnnotationCleanState))
  336. {
  337. cleanState = e.Parameters.GetValue<bool>(ParameterNames.AnnotationCleanState);
  338. if (cleanState)
  339. {
  340. colors.Clear();
  341. authors.Clear();
  342. annotArgsTypes.Clear();
  343. AnnotationListItems.Clear();
  344. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  345. RefreshAnnotationListItems(button);
  346. }
  347. else
  348. {
  349. if (e.Parameters.ContainsKey(ParameterNames.AnnotArgsTypes))
  350. {
  351. annotArgsTypes = e.Parameters.GetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes);
  352. }
  353. if (e.Parameters.ContainsKey(ParameterNames.AnnotationColors))
  354. {
  355. colors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationColors);
  356. }
  357. if (e.Parameters.ContainsKey(ParameterNames.AnnotationAuthor))
  358. {
  359. authors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationAuthor);
  360. }
  361. ObservableCollection<AnnotationHandlerEventArgs> screenAnnotationArgs = SelectAnnotationListItems(annotArgsTypes, colors, authors);
  362. AnnotationListItems.Clear();
  363. AnnotationListItems.AddRange(screenAnnotationArgs);
  364. RefreshAnnotationListItems(button);
  365. }
  366. }
  367. }
  368. else if (e.Result == ButtonResult.Cancel && e.Parameters != null)
  369. {
  370. colors.Clear();
  371. authors.Clear();
  372. annotArgsTypes.Clear();
  373. AnnotationListItems.Clear();
  374. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  375. RefreshAnnotationListItems(button);
  376. }
  377. });
  378. }
  379. }
  380. /// <summary>
  381. /// 刷新列表数据
  382. /// </summary>
  383. /// <param name="button"></param>
  384. private async void RefreshAnnotationListItems(System.Windows.Controls.Button button)
  385. {
  386. switch (AnnotationSortOrder)
  387. {
  388. case AnnotationSortOrder.TimeAscending:
  389. TimeAscendingEvent();
  390. break;
  391. case AnnotationSortOrder.TimeDescending:
  392. TimeDescendingEvent();
  393. break;
  394. case AnnotationSortOrder.PageIndexAscending:
  395. PageSortEvent();
  396. break;
  397. default:
  398. break;
  399. }
  400. if (AnnotationListItems.Count > 0)
  401. {
  402. IsEmptyPanelVisibility = Visibility.Collapsed;
  403. await Task.Delay(2);
  404. //展开数据
  405. ExpandGroupHeader(AnnotationListItems, listBox);
  406. }
  407. else
  408. {
  409. if (button != null)
  410. {
  411. button.IsEnabled = true;
  412. }
  413. IsEmptyPanelVisibility = Visibility.Visible;
  414. //AnnotationListItems.AddRange(currentAnnotationArgs);
  415. //RefreshAnnotationListItems();
  416. }
  417. }
  418. /// <summary>
  419. /// 根据条件筛选列表数据
  420. /// </summary>
  421. /// <param name="annotArgsTypes"></param>
  422. /// <param name="colors"></param>
  423. /// <param name="authors"></param>
  424. /// <returns></returns>
  425. private ObservableCollection<AnnotationHandlerEventArgs> SelectAnnotationListItems(List<AnnotArgsType> annotArgsTypes, List<string> colors, List<string> authors)
  426. {
  427. ObservableCollection<AnnotationHandlerEventArgs> annotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  428. #region 类型 颜色 作者
  429. if (annotArgsTypes.Count > 0 && colors.Count > 0 && authors.Count > 0)
  430. {
  431. foreach (var item in CurrentAnnotationArgs)
  432. {
  433. foreach (var type in annotArgsTypes)
  434. {
  435. foreach (var color in colors)
  436. {
  437. foreach (var author in authors)
  438. {
  439. if (item.EventType == type && item.Author == author)
  440. {
  441. SelectAnnotationColors(item, color, annotationArgs);
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. #endregion 类型 颜色 作者
  449. #region 颜色 作者
  450. else if (colors.Count > 0 && authors.Count > 0)
  451. {
  452. foreach (var item in CurrentAnnotationArgs)
  453. {
  454. foreach (var color in colors)
  455. {
  456. foreach (var author in authors)
  457. {
  458. if (item.Author == author)
  459. {
  460. SelectAnnotationColors(item, color, annotationArgs);
  461. }
  462. }
  463. }
  464. }
  465. }
  466. #endregion 颜色 作者
  467. #region 类型 作者
  468. else if (annotArgsTypes.Count > 0 && authors.Count > 0)
  469. {
  470. foreach (var item in CurrentAnnotationArgs)
  471. {
  472. foreach (var type in annotArgsTypes)
  473. {
  474. foreach (var author in authors)
  475. {
  476. if (item.EventType == type && item.Author == author)
  477. {
  478. annotationArgs.Add(item);
  479. }
  480. }
  481. }
  482. }
  483. }
  484. #endregion 类型 作者
  485. #region 类型 颜色
  486. else if (annotArgsTypes.Count > 0 && colors.Count > 0)
  487. {
  488. foreach (var item in CurrentAnnotationArgs)
  489. {
  490. foreach (var type in annotArgsTypes)
  491. {
  492. foreach (var color in colors)
  493. {
  494. if (item.EventType == type)
  495. {
  496. SelectAnnotationColors(item, color, annotationArgs);
  497. }
  498. }
  499. }
  500. }
  501. }
  502. #endregion 类型 颜色
  503. #region 类型
  504. else if (annotArgsTypes.Count > 0)
  505. {
  506. foreach (var item in CurrentAnnotationArgs)
  507. {
  508. foreach (var type in annotArgsTypes)
  509. {
  510. if (item.EventType == type)
  511. {
  512. annotationArgs.Add(item);
  513. }
  514. }
  515. }
  516. }
  517. #endregion 类型
  518. #region 颜色
  519. else if (colors.Count > 0)
  520. {
  521. foreach (var item in CurrentAnnotationArgs)
  522. {
  523. foreach (var color in colors)
  524. {
  525. SelectAnnotationColors(item, color, annotationArgs);
  526. }
  527. }
  528. }
  529. #endregion 颜色
  530. #region 作者
  531. else if (authors.Count > 0)
  532. {
  533. foreach (var item in CurrentAnnotationArgs)
  534. {
  535. foreach (var author in authors)
  536. {
  537. if (item.Author == author)
  538. {
  539. annotationArgs.Add(item);
  540. }
  541. }
  542. }
  543. }
  544. #endregion 作者
  545. return annotationArgs;
  546. }
  547. /// <summary>
  548. /// 根据颜色筛选注释
  549. /// </summary>
  550. /// <param name="item"></param>
  551. /// <param name="color"></param>
  552. /// <param name="annotationArgs"></param>
  553. private void SelectAnnotationColors(AnnotationHandlerEventArgs item, string color, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  554. {
  555. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  556. switch (item.EventType)
  557. {
  558. case AnnotArgsType.AnnotFreeText://文本
  559. if (data is FreeTextAnnotArgs textAnnotArgs)
  560. {
  561. AddScreenAnnotationArgs(textAnnotArgs.FontColor, color, item, annotationArgs);
  562. }
  563. break;
  564. case AnnotArgsType.AnnotHighlight://高亮
  565. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  566. {
  567. AddScreenAnnotationArgs(highlightAnnotArgs.Color, color, item, annotationArgs);
  568. }
  569. break;
  570. case AnnotArgsType.AnnotFreehand://手绘
  571. if (data is FreehandAnnotArgs freehandAnnotArgs)
  572. {
  573. AddScreenAnnotationArgs(freehandAnnotArgs.InkColor, color, item, annotationArgs);
  574. }
  575. break;
  576. case AnnotArgsType.AnnotSquiggly://波浪线
  577. break;
  578. case AnnotArgsType.AnnotStamp://图章
  579. break;
  580. case AnnotArgsType.AnnotStrikeout://删除线
  581. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  582. {
  583. AddScreenAnnotationArgs(textStrikeoutAnnotArgs.Color, color, item, annotationArgs);
  584. }
  585. break;
  586. case AnnotArgsType.AnnotSticky://便签
  587. if (data is StickyAnnotArgs stickyAnnotArgs)
  588. {
  589. AddScreenAnnotationArgs(stickyAnnotArgs.Color, color, item, annotationArgs);
  590. }
  591. break;
  592. case AnnotArgsType.AnnotUnderline://下划线
  593. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  594. {
  595. AddScreenAnnotationArgs(textUnderlineAnnotArgs.Color, color, item, annotationArgs);
  596. }
  597. break;
  598. case AnnotArgsType.AnnotLine:
  599. //if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  600. //{
  601. // //箭头
  602. //}
  603. //else
  604. //{
  605. // //线
  606. //}
  607. if (data is LineAnnotArgs lineAnnotArgs)
  608. {
  609. AddScreenAnnotationArgs(lineAnnotArgs.LineColor, color, item, annotationArgs);
  610. }
  611. break;
  612. case AnnotArgsType.AnnotSquare://矩形
  613. if (data is SquareAnnotArgs squareAnnotArgs)
  614. {
  615. AddScreenAnnotationArgs(squareAnnotArgs.LineColor, color, item, annotationArgs);
  616. AddScreenAnnotationArgs(squareAnnotArgs.BgColor, color, item, annotationArgs);
  617. }
  618. break;
  619. case AnnotArgsType.AnnotCircle://圆
  620. if (data is CircleAnnotArgs circleAnnotArgs)
  621. {
  622. AddScreenAnnotationArgs(circleAnnotArgs.LineColor, color, item, annotationArgs);
  623. AddScreenAnnotationArgs(circleAnnotArgs.BgColor, color, item, annotationArgs);
  624. }
  625. break;
  626. }
  627. }
  628. /// <summary>
  629. /// 对比颜色
  630. /// </summary>
  631. /// <param name="color1"></param>
  632. /// <param name="color"></param>
  633. /// <param name="item"></param>
  634. /// <param name="annotationArgs"></param>
  635. private void AddScreenAnnotationArgs(System.Windows.Media.Color color1, string color, AnnotationHandlerEventArgs item, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  636. {
  637. if (color1.ToString() == color)
  638. {
  639. annotationArgs.Add(item);
  640. }
  641. }
  642. /// <summary>
  643. /// 添加附注的注释
  644. /// </summary>
  645. /// <param name="obj"></param>
  646. private void AddNotesEvent(object obj)
  647. {
  648. if (obj is ListBoxItem listBoxItem)
  649. {
  650. if (listBoxItem.DataContext is AnnotationHandlerEventArgs args)
  651. {
  652. if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink)
  653. {
  654. DialogParameters value = new DialogParameters();
  655. value.Add(ParameterNames.Annotation, args);
  656. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  657. {
  658. if (e.Result == ButtonResult.OK && e.Parameters != null)
  659. {
  660. PdfViewer.UndoManager.CanSave = true;
  661. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  662. {
  663. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  664. AnnotAttribEvent annotEvent = e.Parameters.GetValue<AnnotAttribEvent>(ParameterNames.AnnotEvent);
  665. listBoxItem.DataContext = annotation;
  666. var annot = AnnotationListItems.FirstOrDefault(q => q.PageIndex == annotation.PageIndex && q.AnnotIndex == annotation.AnnotIndex);
  667. //annotEvent?.UpdateAttrib(AnnotAttrib.NoteText, annotation.MarkupContent);
  668. //annotEvent?.UpdateAnnot();
  669. }
  670. }
  671. });
  672. }
  673. }
  674. }
  675. //if (obj is AnnotationHandlerEventArgs data)
  676. //{
  677. // if (data != null)
  678. // {
  679. // if (data.EventType != AnnotArgsType.AnnotSticky)
  680. // {
  681. // DialogParameters value = new DialogParameters();
  682. // value.Add(ParameterNames.Annotation, data);
  683. // dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  684. // {
  685. // if (e.Result == ButtonResult.OK && e.Parameters != null)
  686. // {
  687. // //PdfViewer.UndoManager.CanSave = true;
  688. // // if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  689. // // {
  690. // // AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  691. // // //AnnotAttribEvent annotEvent = e.Parameters.GetValue<AnnotAttribEvent>(ParameterNames.AnnotEvent);
  692. // // //annotEvent?.UpdateAttrib(AnnotAttrib.NoteText, annotation.MarkupContent);
  693. // // //annotEvent?.UpdateAnnot();
  694. // // }
  695. // }
  696. // });
  697. // }
  698. // //if(data.EventType == AnnotArgsType.AnnotFreeText)
  699. // //{
  700. // // ListBoxItem myListBoxItem = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromItem(data));
  701. // // TextBlock txbContent = CommonHelper.FindVisualChild<TextBlock>(myListBoxItem);
  702. // // TextBox txtContent = CommonHelper.FindVisualChild<TextBox>(myListBoxItem);
  703. // // txbContent.Visibility = Visibility.Collapsed;
  704. // // txtContent.Visibility = Visibility.Visible;
  705. // //}
  706. // }
  707. //}
  708. }
  709. /// <summary>
  710. /// listboxitem鼠标左键点击,显示分组的数据
  711. /// </summary>
  712. /// <param name="obj"></param>
  713. private void ListBoxItem_PreviewMouseLeftButtonDown(object obj)
  714. {
  715. if (obj is ListBoxItem item)
  716. {
  717. var data = item.DataContext as AnnotationHandlerEventArgs;
  718. if (data != null)
  719. {
  720. PdfViewer.SelectAnnotation(data.PageIndex, data.AnnotIndex);
  721. }
  722. }
  723. }
  724. public async void UpdateAddedAnnot(int pageIndex, int annotIndex)
  725. {
  726. var annots = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  727. foreach (var item in annots)
  728. {
  729. if (item.AnnotIndex == annotIndex && item.EventType != AnnotArgsType.AnnotRedaction)
  730. {
  731. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  732. if (args.AnnotHandlerEventArgs != null)
  733. {
  734. AnnotationListItems.Add(args);
  735. CurrentAnnotationArgs.Add(args);
  736. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  737. ExpandGroupHeader(args, listBox);
  738. listBox.SelectedItem = item;
  739. await Task.Delay(1);//不加延时 会有不滚动的现象
  740. listBox.ScrollIntoView(item);
  741. if (!listBox.SelectedItems.Contains(args))
  742. {
  743. listBox.SelectedItem = args;
  744. //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  745. }
  746. }
  747. }
  748. }
  749. if (IsEmptyPanelVisibility == Visibility.Visible && AnnotationListItems.Count > 0)
  750. {
  751. IsEmptyPanelVisibility = Visibility.Collapsed;
  752. }
  753. }
  754. public async void UpdateModifiedAnnot(int pageIndex, int annotIndex, bool isDelete)
  755. {
  756. try
  757. {
  758. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  759. if (isDelete && items.Count == 0)//当前页的最后一次删除
  760. {
  761. for (int k = 0; k < AnnotationListItems.Count; k++)
  762. {
  763. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  764. {
  765. AnnotationListItems.RemoveAt(k);
  766. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  767. CurrentAnnotationArgs.Remove(annotation1);
  768. UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  769. return;
  770. }
  771. }
  772. }
  773. if (isDelete)//删除
  774. {
  775. for (int k = 0; k < AnnotationListItems.Count; k++)
  776. {
  777. //不能加item[j].annoteIndex = annotIndex 删除后必匹配不上
  778. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  779. {
  780. AnnotationListItems.RemoveAt(k);
  781. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  782. CurrentAnnotationArgs.Remove(annotation1);
  783. UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  784. return;
  785. }
  786. }
  787. }
  788. for (int j = 0; j < items.Count; j++)
  789. {
  790. for (int k = 0; k < AnnotationListItems.Count; k++)
  791. {
  792. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex && items[j].AnnotIndex == annotIndex)
  793. {
  794. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
  795. AnnotationListItems[k] = args;
  796. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  797. for (int i = 0; i < CurrentAnnotationArgs.Count; i++)
  798. {
  799. if (annotation1 == CurrentAnnotationArgs[i])
  800. {
  801. CurrentAnnotationArgs[i] = args;
  802. break;
  803. }
  804. }
  805. if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
  806. {
  807. listBox.SelectedItem = AnnotationListItems[k];
  808. //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  809. }
  810. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  811. ExpandGroupHeader(AnnotationListItems[k], listBox);
  812. await Task.Delay(1);//不加延时 会有不滚动的现象
  813. listBox.ScrollIntoView(AnnotationListItems[k]);
  814. }
  815. }
  816. }
  817. }
  818. catch { }
  819. }
  820. /// <summary>
  821. /// 展开item所在分组
  822. /// </summary>
  823. private void ExpandGroupHeader(AnnotationHandlerEventArgs item, ListBox listBox)
  824. {
  825. try
  826. {
  827. var groups = listBox.Items.Groups;
  828. for (int i = 0; i < groups.Count; i++)
  829. {
  830. var l = groups[i] as CollectionViewGroup;
  831. if (l.Items.Contains(item))
  832. {
  833. var scroller = GetScrollHost(listBox);
  834. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  835. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  836. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  837. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  838. if (g != null)
  839. g.IsExpanded = true;
  840. }
  841. }
  842. }
  843. catch { }
  844. }
  845. /// <summary>
  846. /// 页面加载时
  847. /// </summary>
  848. /// <param name="obj"></param>
  849. private void Loaded(object obj)
  850. {
  851. if (obj is CompositeCommandParameter composite)
  852. {
  853. if (composite.Parameter is ListBox listBox)
  854. {
  855. this.listBox = listBox;
  856. SetGroupHeader(listBox);
  857. }
  858. }
  859. }
  860. public bool IsNavigationTarget(NavigationContext navigationContext)
  861. {
  862. return true;
  863. }
  864. public void OnNavigatedFrom(NavigationContext navigationContext)
  865. {
  866. }
  867. public void OnNavigatedTo(NavigationContext navigationContext)
  868. {
  869. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  870. var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  871. if (pdfview != null && viewContentViewModel != null)
  872. {
  873. ViewContentViewModel = viewContentViewModel;
  874. PdfViewer = pdfview;
  875. AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>();
  876. AnnotationListItems = GetDocumentAnnotionList();
  877. CurrentAnnotationArgs.AddRange(AnnotationListItems);
  878. AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  879. }
  880. }
  881. /// <summary>
  882. /// 默认按照PageIndex,分组 排序
  883. /// </summary>
  884. /// <param name="listBox"></param>
  885. private async void SetGroupHeader(ListBox listBox)
  886. {
  887. //按照PageIndex,分组 排序
  888. ICollectionView iCollectionView = CollectionViewSource.GetDefaultView(AnnotationListItems);
  889. iCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotationHandlerEventArgs.PageIndex)));
  890. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  891. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  892. if (AnnotationListItems.Count > 0)
  893. {
  894. IsEmptyPanelVisibility = Visibility.Collapsed;
  895. await Task.Delay(5);
  896. //展开数据
  897. ExpandGroupHeader(AnnotationListItems, listBox);
  898. }
  899. else
  900. {
  901. IsEmptyPanelVisibility = Visibility.Visible;
  902. }
  903. }
  904. /// <summary>
  905. /// 展开列表项
  906. /// </summary>
  907. /// <param name="annotationListItems"></param>
  908. /// <param name="listBox"></param>
  909. private void ExpandGroupHeader(ObservableCollection<AnnotationHandlerEventArgs> annotationListItems, ListBox listBox)
  910. {
  911. try
  912. {
  913. foreach (var item in annotationListItems)
  914. {
  915. var groups = listBox.Items.Groups;
  916. for (int i = 0; i < groups.Count; i++)
  917. {
  918. var group = groups[i] as CollectionViewGroup;
  919. if (group.Items.Contains(item))
  920. {
  921. var scroller = GetScrollHost(listBox);
  922. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  923. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  924. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  925. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  926. if (g != null)
  927. {
  928. g.IsExpanded = true;
  929. }
  930. }
  931. }
  932. }
  933. }
  934. catch { }
  935. }
  936. private ScrollViewer GetScrollHost(ListBox listBox)
  937. {
  938. if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
  939. {
  940. int s = VisualTreeHelper.GetChildrenCount(listBox);
  941. Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
  942. if (border != null)
  943. {
  944. return VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
  945. }
  946. }
  947. return null;
  948. }
  949. /// <summary>
  950. /// 获取listbox绑定数据
  951. /// </summary>
  952. /// <returns></returns>
  953. private ObservableCollection<AnnotationHandlerEventArgs> GetDocumentAnnotionList()
  954. {
  955. ObservableCollection<AnnotationHandlerEventArgs> list = new ObservableCollection<AnnotationHandlerEventArgs>();
  956. for (int i = 0; i < PdfViewer.Document.PageCount; i++)
  957. {
  958. var items = PdfViewer.GetAnnotCommentList(i, PdfViewer.Document);
  959. foreach (var item in items)
  960. {
  961. //原型图上,目前对波浪线的类型,在注释列表不显示
  962. if (item.EventType != AnnotArgsType.AnnotRedaction && item.EventType != AnnotArgsType.AnnotSquiggly)
  963. {
  964. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  965. if (args.AnnotHandlerEventArgs != null)
  966. {
  967. list.Add(args);
  968. }
  969. }
  970. }
  971. }
  972. return list;
  973. }
  974. private AnnotationHandlerEventArgs GetAddAnnotEventArgs(AnnotHandlerEventArgs item)
  975. {
  976. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  977. if (item.EventType == AnnotArgsType.AnnotFreehand)
  978. {
  979. WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
  980. args.WriteableBitmap = bitmap;
  981. }
  982. args.AnnotHandlerEventArgs = item;
  983. args.PageIndex = item.PageIndex;
  984. args.AnnotIndex = item.AnnotIndex;
  985. args.EventType = item.EventType;
  986. args.CreateTime = item.CreateTime;
  987. args.UpdateTime = item.UpdateTime;
  988. args.Content = item.Content;
  989. args.MarkupContent = item.MarkupContent;
  990. args.Author = item.Author;
  991. args.Locked = item.Locked;
  992. args.ReadOnly = item.ReadOnly;
  993. args.FormField = item.FormField;
  994. args.Document = PdfViewer.Document;
  995. return args;
  996. }
  997. /// <summary>
  998. /// 获取手绘图案
  999. /// </summary>
  1000. /// <param name="doc"></param>
  1001. /// <param name="pageIndex"></param>
  1002. /// <param name="annotIndex"></param>
  1003. /// <returns></returns>
  1004. public WriteableBitmap GetAnnotImage(CPDFDocument doc, int pageIndex, int annotIndex)
  1005. {
  1006. if (doc == null)
  1007. {
  1008. return null;
  1009. }
  1010. CPDFPage docPage = doc.PageAtIndex(pageIndex, false);
  1011. if (docPage == null)
  1012. {
  1013. return null;
  1014. }
  1015. List<CPDFAnnotation> docAnnots = docPage.GetAnnotations();
  1016. foreach (CPDFAnnotation annot in docAnnots)
  1017. {
  1018. if (docAnnots.IndexOf(annot) == annotIndex)
  1019. {
  1020. CRect rawRect = annot.GetRect();
  1021. double scaleDpi = 96.0 / 72.0;
  1022. Rect paintRect = new Rect(rawRect.left * scaleDpi, rawRect.top * scaleDpi, rawRect.width() * scaleDpi, rawRect.height() * scaleDpi);
  1023. int drawWidth = (int)paintRect.Width;
  1024. int drawHeight = (int)paintRect.Height;
  1025. byte[] bitmapArray = new byte[drawWidth * drawHeight * 4];
  1026. annot.RenderAnnot(drawWidth, drawHeight, bitmapArray);
  1027. WriteableBitmap wirteBitmap = new WriteableBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Bgra32, null);
  1028. wirteBitmap.WritePixels(new Int32Rect(0, 0, drawWidth, drawHeight), bitmapArray, wirteBitmap.BackBufferStride, 0);
  1029. return wirteBitmap;
  1030. }
  1031. }
  1032. return null;
  1033. }
  1034. /// <summary>
  1035. /// listbox的itemsource发生变化时
  1036. /// </summary>
  1037. /// <param name="sender"></param>
  1038. /// <param name="e"></param>
  1039. private void AnnotationListItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  1040. {
  1041. if (sender is ObservableCollection<AnnotationHandlerEventArgs> obsSender)
  1042. {
  1043. //currentAnnotationArgs.Clear();
  1044. //currentAnnotationArgs.AddRange(obsSender);
  1045. if (obsSender.Count < 1)
  1046. {
  1047. IsEmptyPanelVisibility = Visibility.Visible;
  1048. //currentAnnotationArgs.Clear();
  1049. }
  1050. else
  1051. {
  1052. IsEmptyPanelVisibility = Visibility.Collapsed;
  1053. }
  1054. }
  1055. else
  1056. {
  1057. IsEmptyPanelVisibility = Visibility.Visible;
  1058. }
  1059. }
  1060. }
  1061. }