AnnotationContentViewModel.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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.PowerPoint;
  11. using Microsoft.Office.Interop.Word;
  12. using PDF_Master.CustomControl;
  13. using PDF_Master.DataConvert;
  14. using PDF_Master.EventAggregators;
  15. using PDF_Master.Helper;
  16. using PDF_Master.Model;
  17. using PDF_Master.Model.BOTA;
  18. using PDF_Master.Views.BOTA;
  19. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  20. using PDF_Master.Views.Scan;
  21. using Prism.Commands;
  22. using Prism.Events;
  23. using Prism.Mvvm;
  24. using Prism.Regions;
  25. using Prism.Services.Dialogs;
  26. using System;
  27. using System.Collections;
  28. using System.Collections.Generic;
  29. using System.Collections.ObjectModel;
  30. using System.ComponentModel;
  31. using System.Configuration;
  32. using System.Drawing;
  33. using System.IO;
  34. using System.Linq;
  35. using System.Management.Instrumentation;
  36. using System.Text;
  37. using System.Threading.Tasks;
  38. using System.Windows;
  39. using System.Windows.Annotations;
  40. using System.Windows.Annotations.Storage;
  41. using System.Windows.Controls;
  42. using System.Windows.Data;
  43. using System.Windows.Documents;
  44. using System.Windows.Forms;
  45. using System.Windows.Input;
  46. using System.Windows.Markup;
  47. using System.Windows.Media;
  48. using System.Windows.Media.Imaging;
  49. using System.Windows.Media.Media3D;
  50. using System.Windows.Shapes;
  51. using static Dropbox.Api.Files.SearchMatchType;
  52. using static Dropbox.Api.TeamLog.SpaceCapsType;
  53. using static System.Net.Mime.MediaTypeNames;
  54. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  55. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
  56. using Border = System.Windows.Controls.Border;
  57. using ListBox = System.Windows.Controls.ListBox;
  58. using Task = System.Threading.Tasks.Task;
  59. using TextBox = System.Windows.Controls.TextBox;
  60. using Winform = System.Windows.Forms;
  61. namespace PDF_Master.ViewModels.BOTA
  62. {
  63. public class AnnotationContentViewModel : BindableBase, INavigationAware
  64. {
  65. #region 文案
  66. private string T_expand;
  67. public string T_Expand
  68. {
  69. get { return T_expand; }
  70. set
  71. {
  72. SetProperty(ref T_expand, value);
  73. }
  74. }
  75. private string T_title;
  76. public string T_Title
  77. {
  78. get { return T_title; }
  79. set
  80. {
  81. SetProperty(ref T_title, value);
  82. }
  83. }
  84. private string T_collapse;
  85. public string T_Collapse
  86. {
  87. get { return T_collapse; }
  88. set
  89. {
  90. SetProperty(ref T_collapse, value);
  91. }
  92. }
  93. private string T_import;
  94. public string T_Import
  95. {
  96. get { return T_import; }
  97. set
  98. {
  99. SetProperty(ref T_import, value);
  100. }
  101. }
  102. private string T_copyText;
  103. public string T_CopyText
  104. {
  105. get { return T_copyText; }
  106. set
  107. {
  108. SetProperty(ref T_copyText, value);
  109. }
  110. }
  111. private string T_export;
  112. public string T_Export
  113. {
  114. get { return T_export; }
  115. set
  116. {
  117. SetProperty(ref T_export, value);
  118. }
  119. }
  120. private string T_deleteAll;
  121. public string T_DeleteAll
  122. {
  123. get { return T_deleteAll; }
  124. set
  125. {
  126. SetProperty(ref T_deleteAll, value);
  127. }
  128. }
  129. private string T_emptyTitle;
  130. public string T_EmptyTitle
  131. {
  132. get { return T_emptyTitle; }
  133. set
  134. {
  135. SetProperty(ref T_emptyTitle, value);
  136. }
  137. }
  138. private string T_emptyContext;
  139. public string T_EmptyContext
  140. {
  141. get { return T_emptyContext; }
  142. set
  143. {
  144. SetProperty(ref T_emptyContext, value);
  145. }
  146. }
  147. private string T_delete;
  148. public string T_Delete
  149. {
  150. get { return T_delete; }
  151. set
  152. {
  153. SetProperty(ref T_delete, value);
  154. }
  155. }
  156. private Visibility screen = Visibility.Collapsed;
  157. /// <summary>
  158. /// 是否有筛选条件
  159. /// </summary>
  160. public Visibility Screen
  161. {
  162. get { return screen; }
  163. set
  164. {
  165. SetProperty(ref screen, value);
  166. }
  167. }
  168. private void InitString()
  169. {
  170. T_Expand = App.MainPageLoader.GetString("Annotation_MenuExpand");
  171. T_Collapse = App.MainPageLoader.GetString("Annotation_MenuCollapse");
  172. T_Import = App.MainPageLoader.GetString("Annotation_MenuImport");
  173. T_Export = App.MainPageLoader.GetString("Annotation_MenuExport");
  174. T_DeleteAll = App.MainPageLoader.GetString("Annotation_MenuDeleteAll");
  175. T_EmptyTitle = App.MainPageLoader.GetString("Annotation_EmptyTitle");
  176. T_EmptyContext = App.MainPageLoader.GetString("Annotation_EmptyContext");
  177. T_CopyText = App.MainPageLoader.GetString("Annotation_MenuCopyText");
  178. T_Delete = App.MainPageLoader.GetString("Annotation_MenuDelete");
  179. T_Title = App.MainPageLoader.GetString("Annotation_Title");
  180. }
  181. #endregion 文案
  182. private ListBox listBox;
  183. private IRegionManager region;
  184. private IDialogService dialogs;
  185. private IEventAggregator events;
  186. private Visibility isEmptyPanelVisibility = Visibility.Visible;
  187. public ViewContentViewModel ViewContentViewModel { get; set; }
  188. public CPDFViewer PdfViewer { get; set; }
  189. public Visibility IsEmptyPanelVisibility
  190. {
  191. get { return isEmptyPanelVisibility; }
  192. set
  193. {
  194. SetProperty(ref isEmptyPanelVisibility, value);
  195. }
  196. }
  197. private Visibility isHideAnnotPanelVisibility = Visibility.Collapsed;
  198. public Visibility IsHideAnnotPanelVisibility
  199. {
  200. get { return isHideAnnotPanelVisibility; }
  201. set
  202. {
  203. SetProperty(ref isHideAnnotPanelVisibility, value);
  204. }
  205. }
  206. private ObservableCollection<AnnotationHandlerEventArgs> currentAnnotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  207. public ObservableCollection<AnnotationHandlerEventArgs> CurrentAnnotationLists { get => currentAnnotationArgs; set => currentAnnotationArgs = value; }
  208. private AnnotationSortOrder annotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  209. public AnnotationSortOrder AnnotationSortOrder
  210. {
  211. get { return annotationSortOrder; }
  212. set { annotationSortOrder = value; }
  213. }
  214. private ObservableCollection<AnnotationHandlerEventArgs> annotationListItems;
  215. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems
  216. {
  217. get { return annotationListItems; }
  218. set
  219. {
  220. SetProperty(ref annotationListItems, value);
  221. }
  222. }
  223. private bool CanIsEnabled()
  224. {
  225. if (AnnotationListItems.Count > 0)
  226. {
  227. return true;
  228. }
  229. else
  230. {
  231. return false;
  232. }
  233. }
  234. private List<string> colors = new List<string>();
  235. private List<string> authors = new List<string>();
  236. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  237. public DelegateCommand<object> LoadedCommand { get; set; }
  238. public DelegateCommand<object> ListBoxItemPreviewMouseLeftButtonDown { get; set; }
  239. public DelegateCommand<object> AddNotesCommand { get; set; }
  240. public DelegateCommand<object> ScreenCommand { get; set; }
  241. public DelegateCommand ExportCommentsCommand { get; set; }
  242. public DelegateCommand ImportCommentsCommand { get; set; }
  243. public DelegateCommand<object> DeleteCommand { get; set; }
  244. public DelegateCommand DeleteAllCommand { get; set; }
  245. public DelegateCommand PageSortCommand { get; set; }
  246. public DelegateCommand TimeAscendingCommand { get; set; }
  247. public DelegateCommand TimeDescendingCommand { get; set; }
  248. public string Unicode { get; private set; }
  249. private bool IsFirst = true;
  250. public AnnotationContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  251. {
  252. region = regionManager;
  253. dialogs = dialogService;
  254. events = eventAggregator;
  255. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  256. LoadedCommand = new DelegateCommand<object>(Loaded);
  257. ListBoxItemPreviewMouseLeftButtonDown = new DelegateCommand<object>(ListBoxItem_PreviewMouseLeftButtonDown);
  258. AddNotesCommand = new DelegateCommand<object>(AddNotesEvent);
  259. ScreenCommand = new DelegateCommand<object>(ScreenEvent);
  260. ExportCommentsCommand = new DelegateCommand(ExportCommentsEvent, CanIsEnabled).ObservesProperty(() => AnnotationListItems);
  261. ImportCommentsCommand = new DelegateCommand(ImportCommentsEvent);
  262. DeleteCommand = new DelegateCommand<object>(DelegateEvent);
  263. DeleteAllCommand = new DelegateCommand(DeleteAllEvent, CanIsEnabled).ObservesProperty(() => AnnotationListItems);
  264. PageSortCommand = new DelegateCommand(PageSortEvent);
  265. TimeAscendingCommand = new DelegateCommand(TimeAscendingEvent);
  266. TimeDescendingCommand = new DelegateCommand(TimeDescendingEvent);
  267. InitString();
  268. events.GetEvent<RefreshAnnotEvent>().Subscribe(RefreshData, e => e.Unicode == Unicode);
  269. events.GetEvent<PageEditNotifyEvent>().Subscribe(OnNotifyEvent, e => e.Unicode == Unicode && e.Type == NotifyType.PageCountChanged);
  270. }
  271. private void OnNotifyEvent(PageEditNotifyEventArgs obj)
  272. {
  273. RefreshAnnotationListItems();
  274. }
  275. private bool isHiddenAnnot = false;
  276. public void HiddenAnnot()
  277. {
  278. isHiddenAnnot = true;
  279. colors.Clear();
  280. authors.Clear();
  281. annotArgsTypes.Clear();
  282. AnnotationListItems.Clear();
  283. CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
  284. AnnotationListItems.AddRange(CurrentAnnotationLists);
  285. Screen = Visibility.Collapsed;
  286. }
  287. public void DisplayAnnot()
  288. {
  289. isHiddenAnnot = false;
  290. colors.Clear();
  291. authors.Clear();
  292. annotArgsTypes.Clear();
  293. AnnotationListItems.Clear();
  294. //AnnotationListItems = GetDocumentAnnotionList(out ObservableCollection<AnnotationHandlerEventArgs> HideAnnots);
  295. CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
  296. AnnotationListItems.AddRange(CurrentAnnotationLists);
  297. RefreshAnnotationListItems();
  298. Screen = Visibility.Collapsed;
  299. }
  300. /// <summary>
  301. /// 导入注释
  302. /// </summary>
  303. /// <param name="obj"></param>
  304. private async void ImportCommentsEvent()
  305. {
  306. Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  307. dlg.Filter = "PDF|*.xfdf";
  308. dlg.DefaultExt = ".xfdf";
  309. if (dlg.ShowDialog() == true)
  310. {
  311. try
  312. {
  313. string fileName = dlg.FileName;
  314. await Task.Delay(10);
  315. var result = PdfViewer.ImportAnnotationFromXFDFPath(fileName);
  316. if (result == false)
  317. {
  318. //MessageBoxEx.Show("导入失败", "", Winform.MessageBoxButtons.OK, Winform.MessageBoxIcon.Error);
  319. AlertsMessage alertsMessage = new AlertsMessage();
  320. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Dialog_Hint"), App.MainPageLoader.GetString("Annot_ExportFailWarning"), App.ServiceLoader.GetString("Text_ok"));
  321. return;
  322. }
  323. PdfViewer.ReloadVisibleAnnots();
  324. //提取出来的注释文件 时间为空 则显示未系统当前时间
  325. CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
  326. //BOTA,注释列表,添加在页面上的注释要默认按照页面上的位置排序,从上往下,从左往右排列
  327. //CurrentAnnotationLists = new ObservableCollection<AnnotationHandlerEventArgs>(CurrentAnnotationLists.OrderBy(item => item.ClientRect.X).ThenBy(item => item.ClientRect.Y));
  328. AnnotationListItems.Clear();
  329. AnnotationListItems.AddRange(CurrentAnnotationLists);
  330. await Task.Delay(5);
  331. RefreshAnnotationListItems(null);
  332. PdfViewer.UndoManager.CanSave = true;
  333. }
  334. catch (Exception ex)
  335. {
  336. AlertsMessage alertsMessage = new AlertsMessage();
  337. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Dialog_Hint"), App.MainPageLoader.GetString("Annot_ExportFailWarning")+ex.Message, App.ServiceLoader.GetString("Text_ok"));
  338. }
  339. }
  340. }
  341. /// <summary>
  342. /// 时间倒序
  343. /// </summary>
  344. private void TimeDescendingEvent()
  345. {
  346. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  347. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  348. v.GroupDescriptions.Clear();
  349. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  350. v.SortDescriptions.Clear();
  351. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Descending));
  352. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Descending));
  353. AnnotationSortOrder = AnnotationSortOrder.TimeDescending;
  354. }
  355. /// <summary>
  356. /// 时间正序
  357. /// </summary>
  358. private void TimeAscendingEvent()
  359. {
  360. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  361. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  362. v.GroupDescriptions.Clear();
  363. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  364. v.SortDescriptions.Clear();
  365. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Ascending));
  366. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  367. AnnotationSortOrder = AnnotationSortOrder.TimeAscending;
  368. }
  369. /// <summary>
  370. /// 页面排序
  371. /// </summary>
  372. private void PageSortEvent()
  373. {
  374. if (AnnotationListItems == null) return;
  375. if (AnnotationListItems.Count < 0) return;
  376. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  377. v.GroupDescriptions.Clear();
  378. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.PageIndex)));
  379. v.SortDescriptions.Clear();
  380. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  381. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  382. AnnotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  383. }
  384. /// <summary>
  385. /// 删除所有注释
  386. /// </summary>
  387. private void DeleteAllEvent()
  388. {
  389. //调用集中删除的接口 方便一次性undo
  390. Dictionary<int, List<int>> deleteLists = new Dictionary<int, List<int>>();
  391. for (int i = 0; i < AnnotationListItems.Count; i++)
  392. {
  393. AnnotationHandlerEventArgs item = AnnotationListItems[i] as AnnotationHandlerEventArgs;
  394. if (!deleteLists.ContainsKey(item.PageIndex))
  395. {
  396. deleteLists.Add(item.PageIndex, new List<int>() { item.AnnotIndex });
  397. }
  398. else
  399. {
  400. var pagelist = deleteLists[item.PageIndex];
  401. pagelist.Add(item.AnnotIndex);
  402. }
  403. }
  404. AlertsMessage alertsMessage = new AlertsMessage();
  405. alertsMessage.ShowDialog(" ", App.MainPageLoader.GetString("DeleteAllAnnotation_Warning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  406. if (alertsMessage.result == ContentResult.Ok)
  407. {
  408. PdfViewer.RemovePageAnnot(deleteLists);
  409. AnnotationListItems.Clear();
  410. CurrentAnnotationLists.Clear();
  411. PdfViewer.UndoManager.CanSave = true;
  412. }
  413. }
  414. /// <summary>
  415. /// 删除注释,单个/多个
  416. /// </summary>
  417. /// <param name="obj"></param>
  418. private void DelegateEvent(object obj)
  419. {
  420. if (obj is AnnotationHandlerEventArgs annotation)
  421. {
  422. if (annotation != null)
  423. {
  424. var result = PdfViewer.RemovePageAnnot(annotation.PageIndex, annotation.AnnotIndex);
  425. if (result)
  426. {
  427. RemoveItem(annotation);
  428. }
  429. }
  430. }
  431. }
  432. public void RemoveItem(AnnotationHandlerEventArgs annotation)
  433. {
  434. AnnotationListItems.Remove(annotation);
  435. var annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
  436. CurrentAnnotationLists.Remove(annotation1);
  437. //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
  438. UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
  439. PdfViewer.UndoManager.CanSave = true;
  440. }
  441. /// <summary>
  442. /// 删除之后,更新
  443. /// </summary>
  444. /// <param name="pageIndex"></param>
  445. /// <param name="annoteIndex"></param>
  446. private void UpdateAnnotListAfterDelete(int pageIndex, int annoteIndex)
  447. {
  448. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  449. for (int j = 0; j < items.Count; j++)//用修改赋值的方式 可以解决删除后表头折叠的问题
  450. {
  451. if (items[j].AnnotIndex >= annoteIndex)//只需要更新比删除元素索引大的注释
  452. {
  453. for (int k = 0; k < AnnotationListItems.Count; k++)
  454. {
  455. //相当于将后面的索引-1
  456. if (AnnotationListItems[k].PageIndex == pageIndex &&
  457. AnnotationListItems[k].AnnotIndex == (items[j].AnnotIndex + 1) &&
  458. string.Equals(AnnotationListItems[k].MarkupContent, items[j].MarkupContent) &&
  459. string.Equals(AnnotationListItems[k].Content, items[j].Content) &&
  460. string.Equals(AnnotationListItems[k].CreateTime, items[j].CreateTime) &&
  461. string.Equals(AnnotationListItems[k].Author, items[j].Author)
  462. )
  463. {
  464. AnnotationListItems[k].AnnotHandlerEventArgs = items[j];
  465. AnnotationListItems[k].PageIndex = items[j].PageIndex;
  466. AnnotationListItems[k].AnnotIndex = items[j].AnnotIndex;
  467. AnnotationListItems[k].EventType = items[j].EventType;
  468. AnnotationListItems[k].CreateTime = items[j].CreateTime;
  469. AnnotationListItems[k].UpdateTime = items[j].UpdateTime;
  470. if (items[j].EventType == AnnotArgsType.AnnotFreehand)
  471. {
  472. BitmapImage bitmap = GetAnnotImage(PdfViewer.Document, items[j].PageIndex, items[j].AnnotIndex);
  473. if (bitmap != null)
  474. AnnotationListItems[k].WriteableBitmap = bitmap;
  475. }
  476. AnnotationListItems[k].Content = items[j].Content;
  477. AnnotationListItems[k].MarkupContent = items[j].MarkupContent;
  478. AnnotationListItems[k].Author = items[j].Author;
  479. AnnotationListItems[k].Locked = items[j].Locked;
  480. AnnotationListItems[k].ReadOnly = items[j].ReadOnly;
  481. AnnotationListItems[k].FormField = items[j].FormField;
  482. AnnotationListItems[k].Document = PdfViewer.Document;
  483. }
  484. }
  485. }
  486. }
  487. }
  488. /// <summary>
  489. /// 导出注释
  490. /// </summary>
  491. /// <param name="obj"></param>
  492. private void ExportCommentsEvent()
  493. {
  494. if (ViewContentViewModel.CanSave)
  495. {
  496. ViewContentViewModel.SaveFile.Execute();
  497. }
  498. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  499. dlg.Filter = "PDF|*.xfdf";
  500. dlg.DefaultExt = ".xfdf";
  501. dlg.FileName = PdfViewer.Document.FileName;
  502. if (dlg.ShowDialog() == true)
  503. {
  504. string fileName = dlg.FileName;
  505. var result = PdfViewer.ExportAnnotationToXFDFPath(fileName);
  506. if (result)
  507. {
  508. AlertsMessage alertsMessage = new AlertsMessage();
  509. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Dialog_Hint"), App.MainPageLoader.GetString("Annot_ExportSuccess"), App.ServiceLoader.GetString("Text_ok"));
  510. }
  511. else
  512. {
  513. AlertsMessage alertsMessage = new AlertsMessage();
  514. alertsMessage.ShowDialog(App.MainPageLoader.GetString("Dialog_Hint"), App.MainPageLoader.GetString("Annot_ExportSuccess"), App.ServiceLoader.GetString("Text_ok"));
  515. }
  516. }
  517. }
  518. /// <summary>
  519. /// 筛选注释
  520. /// </summary>
  521. /// <param name="obj"></param>
  522. private void ScreenEvent(object obj)
  523. {
  524. if (obj is System.Windows.Controls.Button button)
  525. {
  526. DialogParameters value = new DialogParameters();
  527. value.Add(ParameterNames.AnnotationList, CurrentAnnotationLists);
  528. value.Add(ParameterNames.AnnotArgsTypes, annotArgsTypes);
  529. value.Add(ParameterNames.AnnotationColors, colors);
  530. value.Add(ParameterNames.AnnotationAuthor, authors);
  531. dialogs.ShowDialog(DialogNames.ScreenAnnotationDialog, value, e =>
  532. {
  533. if (e.Result == ButtonResult.OK && e.Parameters != null)
  534. {
  535. if (e.Parameters.ContainsKey(ParameterNames.AnnotArgsTypes))
  536. {
  537. annotArgsTypes = e.Parameters.GetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes);
  538. }
  539. if (e.Parameters.ContainsKey(ParameterNames.AnnotationColors))
  540. {
  541. colors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationColors);
  542. }
  543. if (e.Parameters.ContainsKey(ParameterNames.AnnotationAuthor))
  544. {
  545. authors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationAuthor);
  546. }
  547. if (annotArgsTypes.Count > 0 || colors.Count > 0 || authors.Count > 0)
  548. {
  549. ObservableCollection<AnnotationHandlerEventArgs> screenAnnotationArgs = SelectAnnotationListItems(annotArgsTypes, colors, authors);
  550. AnnotationListItems.Clear();
  551. AnnotationListItems.AddRange(screenAnnotationArgs);
  552. //BOTA,注释列表,添加在页面上的注释要默认按照页面上的位置排序,从上往下,从左往右排列
  553. //AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>(AnnotationListItems.OrderBy(item => item.ClientRect.Y).ThenBy(item => item.ClientRect.X));
  554. RefreshAnnotationListItems(button);
  555. //AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  556. Screen = Visibility.Visible;
  557. }
  558. else
  559. {
  560. CleanAnnotation(button);
  561. Screen = Visibility.Collapsed;
  562. }
  563. }
  564. else if (e.Result == ButtonResult.Cancel && e.Parameters != null)
  565. {
  566. //CleanAnnotation(button);
  567. }
  568. });
  569. }
  570. }
  571. private void CleanAnnotation(System.Windows.Controls.Button button)
  572. {
  573. colors.Clear();
  574. authors.Clear();
  575. annotArgsTypes.Clear();
  576. AnnotationListItems.Clear();
  577. AnnotationListItems.AddRange(CurrentAnnotationLists);
  578. //BOTA,注释列表,添加在页面上的注释要默认按照页面上的位置排序,从上往下,从左往右排列
  579. //AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>(AnnotationListItems.OrderBy(item => item.ClientRect.Y).ThenBy(item => item.ClientRect.X));
  580. RefreshAnnotationListItems(button);
  581. //AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  582. }
  583. /// <summary>
  584. /// 刷新列表数据
  585. /// </summary>
  586. /// <param name="button"></param>
  587. public async void RefreshAnnotationListItems(System.Windows.Controls.Button button = null)
  588. {
  589. switch (AnnotationSortOrder)
  590. {
  591. case AnnotationSortOrder.TimeAscending:
  592. TimeAscendingEvent();
  593. break;
  594. case AnnotationSortOrder.TimeDescending:
  595. TimeDescendingEvent();
  596. break;
  597. case AnnotationSortOrder.PageIndexAscending:
  598. PageSortEvent();
  599. break;
  600. default:
  601. break;
  602. }
  603. if (AnnotationListItems == null) return;
  604. if (AnnotationListItems.Count > 0)
  605. {
  606. IsEmptyPanelVisibility = Visibility.Collapsed;
  607. await Task.Delay(5);
  608. //展开数据
  609. ExpandGroupHeader(AnnotationListItems, listBox);
  610. }
  611. else
  612. {
  613. if (button != null)
  614. {
  615. button.IsEnabled = true;
  616. }
  617. IsEmptyPanelVisibility = Visibility.Visible;
  618. IsHideAnnotPanelVisibility = Visibility.Visible;
  619. }
  620. }
  621. /// <summary>
  622. /// 根据条件筛选列表数据
  623. /// </summary>
  624. /// <param name="annotArgsTypes"></param>
  625. /// <param name="colors"></param>
  626. /// <param name="authors"></param>
  627. /// <returns></returns>
  628. private ObservableCollection<AnnotationHandlerEventArgs> SelectAnnotationListItems(List<AnnotArgsType> annotArgsTypes, List<string> colors, List<string> authors)
  629. {
  630. ObservableCollection<AnnotationHandlerEventArgs> annotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  631. #region 类型 颜色 作者
  632. if (annotArgsTypes.Count > 0 && colors.Count > 0 && authors.Count > 0)
  633. {
  634. foreach (var item in CurrentAnnotationLists)
  635. {
  636. foreach (var type in annotArgsTypes)
  637. {
  638. foreach (var color in colors)
  639. {
  640. foreach (var author in authors)
  641. {
  642. if (item.EventType == type && item.Author == author)
  643. {
  644. SelectAnnotationColors(item, color, annotationArgs);
  645. }
  646. }
  647. }
  648. }
  649. }
  650. }
  651. #endregion 类型 颜色 作者
  652. #region 颜色 作者
  653. else if (colors.Count > 0 && authors.Count > 0)
  654. {
  655. foreach (var item in CurrentAnnotationLists)
  656. {
  657. foreach (var color in colors)
  658. {
  659. foreach (var author in authors)
  660. {
  661. if (item.Author == author)
  662. {
  663. SelectAnnotationColors(item, color, annotationArgs);
  664. }
  665. }
  666. }
  667. }
  668. }
  669. #endregion 颜色 作者
  670. #region 类型 作者
  671. else if (annotArgsTypes.Count > 0 && authors.Count > 0)
  672. {
  673. foreach (var item in CurrentAnnotationLists)
  674. {
  675. foreach (var type in annotArgsTypes)
  676. {
  677. foreach (var author in authors)
  678. {
  679. if (item.EventType == type && item.Author == author)
  680. {
  681. annotationArgs.Add(item);
  682. }
  683. }
  684. }
  685. }
  686. }
  687. #endregion 类型 作者
  688. #region 类型 颜色
  689. else if (annotArgsTypes.Count > 0 && colors.Count > 0)
  690. {
  691. foreach (var item in CurrentAnnotationLists)
  692. {
  693. foreach (var type in annotArgsTypes)
  694. {
  695. foreach (var color in colors)
  696. {
  697. if (item.EventType == type)
  698. {
  699. SelectAnnotationColors(item, color, annotationArgs);
  700. }
  701. }
  702. }
  703. }
  704. }
  705. #endregion 类型 颜色
  706. #region 类型
  707. else if (annotArgsTypes.Count > 0)
  708. {
  709. foreach (var item in CurrentAnnotationLists)
  710. {
  711. foreach (var type in annotArgsTypes)
  712. {
  713. if (item.EventType == type)
  714. {
  715. annotationArgs.Add(item);
  716. }
  717. }
  718. }
  719. }
  720. #endregion 类型
  721. #region 颜色
  722. else if (colors.Count > 0)
  723. {
  724. foreach (var item in CurrentAnnotationLists)
  725. {
  726. foreach (var color in colors)
  727. {
  728. SelectAnnotationColors(item, color, annotationArgs);
  729. }
  730. }
  731. }
  732. #endregion 颜色
  733. #region 作者
  734. else if (authors.Count > 0)
  735. {
  736. foreach (var item in CurrentAnnotationLists)
  737. {
  738. foreach (var author in authors)
  739. {
  740. if (item.Author == author)
  741. {
  742. annotationArgs.Add(item);
  743. }
  744. }
  745. }
  746. }
  747. #endregion 作者
  748. return annotationArgs;
  749. }
  750. /// <summary>
  751. /// 根据颜色筛选注释
  752. /// </summary>
  753. /// <param name="item"></param>
  754. /// <param name="color"></param>
  755. /// <param name="annotationArgs"></param>
  756. private void SelectAnnotationColors(AnnotationHandlerEventArgs item, string color, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  757. {
  758. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  759. switch (item.EventType)
  760. {
  761. case AnnotArgsType.AnnotFreeText://文本
  762. if (data is FreeTextAnnotArgs textAnnotArgs)
  763. {
  764. AddScreenAnnotationArgs(textAnnotArgs.FontColor, color, item, annotationArgs);
  765. }
  766. break;
  767. case AnnotArgsType.AnnotHighlight://高亮
  768. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  769. {
  770. AddScreenAnnotationArgs(highlightAnnotArgs.Color, color, item, annotationArgs);
  771. }
  772. break;
  773. case AnnotArgsType.AnnotFreehand://手绘
  774. if (data is FreehandAnnotArgs freehandAnnotArgs)
  775. {
  776. AddScreenAnnotationArgs(freehandAnnotArgs.InkColor, color, item, annotationArgs);
  777. }
  778. break;
  779. case AnnotArgsType.AnnotSquiggly://波浪线
  780. break;
  781. case AnnotArgsType.AnnotStamp://图章
  782. break;
  783. case AnnotArgsType.AnnotStrikeout://删除线
  784. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  785. {
  786. AddScreenAnnotationArgs(textStrikeoutAnnotArgs.Color, color, item, annotationArgs);
  787. }
  788. break;
  789. case AnnotArgsType.AnnotSticky://便签
  790. if (data is StickyAnnotArgs stickyAnnotArgs)
  791. {
  792. AddScreenAnnotationArgs(stickyAnnotArgs.Color, color, item, annotationArgs);
  793. }
  794. break;
  795. case AnnotArgsType.AnnotUnderline://下划线
  796. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  797. {
  798. AddScreenAnnotationArgs(textUnderlineAnnotArgs.Color, color, item, annotationArgs);
  799. }
  800. break;
  801. case AnnotArgsType.AnnotLine:
  802. //if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  803. //{
  804. // //箭头
  805. //}
  806. //else
  807. //{
  808. // //线
  809. //}
  810. if (data is LineAnnotArgs lineAnnotArgs)
  811. {
  812. AddScreenAnnotationArgs(lineAnnotArgs.LineColor, color, item, annotationArgs);
  813. }
  814. break;
  815. case AnnotArgsType.AnnotSquare://矩形
  816. if (data is SquareAnnotArgs squareAnnotArgs)
  817. {
  818. AddScreenAnnotationArgs(squareAnnotArgs.LineColor, color, item, annotationArgs);
  819. AddScreenAnnotationArgs(squareAnnotArgs.BgColor, color, item, annotationArgs);
  820. }
  821. break;
  822. case AnnotArgsType.AnnotCircle://圆
  823. if (data is CircleAnnotArgs circleAnnotArgs)
  824. {
  825. AddScreenAnnotationArgs(circleAnnotArgs.LineColor, color, item, annotationArgs);
  826. AddScreenAnnotationArgs(circleAnnotArgs.BgColor, color, item, annotationArgs);
  827. }
  828. break;
  829. }
  830. }
  831. /// <summary>
  832. /// 对比颜色
  833. /// </summary>
  834. /// <param name="color1"></param>
  835. /// <param name="color"></param>
  836. /// <param name="item"></param>
  837. /// <param name="annotationArgs"></param>
  838. private void AddScreenAnnotationArgs(System.Windows.Media.Color color1, string color, AnnotationHandlerEventArgs item, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  839. {
  840. if (color1.ToString() == color)
  841. {
  842. annotationArgs.Add(item);
  843. }
  844. }
  845. /// <summary>
  846. /// 添加附注的注释
  847. /// </summary>
  848. /// <param name="obj"></param>
  849. private void AddNotesEvent(object obj)
  850. {
  851. if (obj is ListBoxItem listBoxItem)
  852. {
  853. if (listBoxItem.DataContext is AnnotationHandlerEventArgs args)
  854. {
  855. //if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink)
  856. if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink/*&&
  857. args.EventType != AnnotArgsType.AnnotHighlight && args.EventType != AnnotArgsType.AnnotUnderline
  858. && args.EventType != AnnotArgsType.AnnotStrikeout*/)
  859. {
  860. DialogParameters value = new DialogParameters();
  861. value.Add(ParameterNames.Annotation, args);
  862. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  863. {
  864. if (e.Result == ButtonResult.OK && e.Parameters != null)
  865. {
  866. PdfViewer.UndoManager.CanSave = true;
  867. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  868. {
  869. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  870. RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  871. }
  872. }
  873. });
  874. }
  875. //else if (args.EventType == AnnotArgsType.AnnotFreeText)
  876. //{
  877. // StackPanel stackPanel = CommonHelper.FindVisualChild<StackPanel>(listBoxItem);
  878. // TextBox textBox = CommonHelper.FindVisualChild<TextBox>(stackPanel);
  879. // TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(stackPanel);
  880. // textBlock.Visibility = Visibility.Collapsed;
  881. // textBox.Visibility = Visibility.Visible;
  882. // textBox.Dispatcher.BeginInvoke(new Action(() =>
  883. // {
  884. // textBox.Focus();
  885. // textBox.SelectAll();
  886. // }));
  887. //}
  888. }
  889. }
  890. }
  891. private async void RefreshOneListItem(AnnotHandlerEventArgs annotation)
  892. {
  893. for (int i = 0; i < AnnotationListItems.Count; i++)
  894. {
  895. if (AnnotationListItems[i].PageIndex == annotation.PageIndex && AnnotationListItems[i].AnnotIndex == annotation.AnnotIndex)
  896. {
  897. AnnotationListItems[i] = GetAddAnnotEventArgs(annotation);
  898. for (int j = 0; j < CurrentAnnotationLists.Count; j++)
  899. {
  900. if (CurrentAnnotationLists[j].PageIndex == annotation.PageIndex && CurrentAnnotationLists[j].AnnotIndex == annotation.AnnotIndex)
  901. {
  902. CurrentAnnotationLists[j] = GetAddAnnotEventArgs(annotation);
  903. break;
  904. }
  905. }
  906. if (!listBox.SelectedItems.Contains(AnnotationListItems[i]))
  907. {
  908. listBox.SelectedItem = AnnotationListItems[i];
  909. }
  910. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  911. ExpandGroupHeader(AnnotationListItems[i], listBox);
  912. await Task.Delay(1);//不加延时 会有不滚动的现象
  913. listBox.ScrollIntoView(AnnotationListItems[i]);
  914. break;
  915. }
  916. }
  917. }
  918. public async void ScrollToAnnot(int pageindex, int annotindex, ListBox AnnotationList)
  919. {
  920. //var list = PdfViewer.GetAnnotCommentList(pageindex, PdfViewer.Document);
  921. for (int i = 0; i < AnnotationList.Items.Count; i++)
  922. {
  923. if(AnnotationList.Items[i] is AnnotationHandlerEventArgs item)
  924. {
  925. if (item.AnnotIndex == annotindex && item.PageIndex == pageindex)
  926. {
  927. //var item = AnnotationList.Items[i] as AnnotationHandlerEventArgs;
  928. if (item.EventType != AnnotArgsType.AnnotLink)
  929. {
  930. //需要手动搜寻在哪一个分组 展开分组头
  931. ExpandGroupHeader(item, AnnotationList);
  932. if (AnnotationList.SelectedItems.IndexOf(item) == -1)
  933. {
  934. AnnotationList.SelectedItem = item;
  935. }
  936. await Task.Delay(1);
  937. AnnotationList.ScrollIntoView(item);
  938. }
  939. }
  940. }
  941. }
  942. }
  943. /// <summary>
  944. /// listboxitem鼠标左键点击,显示分组的数据
  945. /// </summary>
  946. /// <param name="obj"></param>
  947. private void ListBoxItem_PreviewMouseLeftButtonDown(object obj)
  948. {
  949. if (obj is ListBoxItem item)
  950. {
  951. var data = item.DataContext as AnnotationHandlerEventArgs;
  952. if (data != null)
  953. {
  954. PdfViewer.SelectAnnotation(data.PageIndex, data.AnnotIndex);
  955. }
  956. }
  957. if (obj is AnnotationHandlerEventArgs annotation)
  958. {
  959. PdfViewer.SelectAnnotation(annotation.PageIndex, annotation.AnnotIndex);
  960. }
  961. if (obj is Dictionary<int, List<int>> eventArgs)
  962. {
  963. PdfViewer.SelectAnnotation(eventArgs);
  964. }
  965. }
  966. public async void UpdateAddedAnnot(int pageIndex, int annotIndex)
  967. {
  968. var annots = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  969. for (int i = 0; i < annots.Count; i++)
  970. {
  971. AnnotHandlerEventArgs item = annots[i];
  972. if (item.AnnotIndex == annotIndex && item.EventType != AnnotArgsType.AnnotRedaction)
  973. {
  974. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  975. // 注释列表 不显示链接
  976. if (args.AnnotHandlerEventArgs is LinkAnnotArgs)
  977. {
  978. continue;
  979. }
  980. if (args.AnnotHandlerEventArgs != null)
  981. {
  982. AnnotationListItems.Add(args);
  983. CurrentAnnotationLists.Add(args);
  984. await Task.Delay(5);//不加延时 每页的第一个注释不会展开
  985. //添加 时 ,形状、图章、签名,添加后选中
  986. if (args.EventType == AnnotArgsType.AnnotSquare ||
  987. args.EventType == AnnotArgsType.AnnotCircle ||
  988. args.EventType == AnnotArgsType.AnnotLine ||
  989. args.EventType == AnnotArgsType.AnnotStamp
  990. /* ||args.EventType == AnnotArgsType.AnnotLink*/)
  991. {
  992. listBox.SelectedItem = args;
  993. }
  994. ExpandGroupHeader(args, listBox);
  995. // 关闭后选中关闭前的位置
  996. if (ViewContentViewModel.OpenBOTA)
  997. {
  998. await Task.Delay(5);//不加延时 会有不滚动的现象
  999. //events.GetEvent<ScrollIntoAnnotViewEvent>().Publish(new ScrollIntoAnnotViewArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = item });
  1000. listBox.ScrollIntoView(args);
  1001. }
  1002. //if (!listBox.SelectedItems.Contains(args))
  1003. //{
  1004. // listBox.SelectedItem = args;
  1005. // //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  1006. //}
  1007. }
  1008. }
  1009. }
  1010. listBox.UpdateLayout();
  1011. //SetGroupHeader(listBox);
  1012. if (IsEmptyPanelVisibility == Visibility.Visible && AnnotationListItems.Count > 0)
  1013. {
  1014. IsEmptyPanelVisibility = Visibility.Collapsed;
  1015. }
  1016. }
  1017. public void DeleteModifiedAnnot(int pageIndex, int annotIndex)
  1018. {
  1019. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  1020. //if (items.Count == 0)
  1021. //{
  1022. // for (int k = 0; k < AnnotationListItems.Count; k++)
  1023. // {
  1024. // if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  1025. // {
  1026. // AnnotationListItems.RemoveAt(k);
  1027. // AnnotationHandlerEventArgs annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  1028. // CurrentAnnotationLists.Remove(annotation1);
  1029. // UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  1030. // return;
  1031. // }
  1032. // }
  1033. //}
  1034. //else
  1035. //{
  1036. for (int k = 0; k < AnnotationListItems.Count; k++)
  1037. {
  1038. //不能加item[j].annoteIndex = annotIndex 删除后必匹配不上
  1039. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  1040. {
  1041. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  1042. CurrentAnnotationLists.Remove(annotation1);
  1043. AnnotationListItems.RemoveAt(k);
  1044. UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  1045. return;
  1046. }
  1047. }
  1048. //}
  1049. }
  1050. public async void UpdateModifiedAnnot(int pageIndex, int annotIndex/*, bool isDelete*/)
  1051. {
  1052. try
  1053. {
  1054. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  1055. #region 删除
  1056. //if (isDelete && items.Count == 0)//当前页的最后一次删除
  1057. //{
  1058. // for (int k = 0; k < AnnotationListItems.Count; k++)
  1059. // {
  1060. // if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  1061. // {
  1062. // AnnotationListItems.RemoveAt(k);
  1063. // AnnotationHandlerEventArgs annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  1064. // CurrentAnnotationLists.Remove(annotation1);
  1065. // UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  1066. // return;
  1067. // }
  1068. // }
  1069. //}
  1070. //if (isDelete)//删除
  1071. //{
  1072. // for (int k = 0; k < AnnotationListItems.Count; k++)
  1073. // {
  1074. // //不能加item[j].annoteIndex = annotIndex 删除后必匹配不上
  1075. // if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  1076. // {
  1077. // AnnotationListItems.RemoveAt(k);
  1078. // AnnotationHandlerEventArgs annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  1079. // CurrentAnnotationLists.Remove(annotation1);
  1080. // UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  1081. // return;
  1082. // }
  1083. // }
  1084. //}
  1085. #endregion 删除
  1086. for (int j = 0; j < items.Count; j++)
  1087. {
  1088. for (int k = 0; k < AnnotationListItems.Count; k++)
  1089. {
  1090. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex && items[j].AnnotIndex == annotIndex)
  1091. {
  1092. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
  1093. AnnotationListItems[k] = GetAddAnnotEventArgs(items[j]);
  1094. for (int i = 0; i < CurrentAnnotationLists.Count; i++)
  1095. {
  1096. if (CurrentAnnotationLists[i].PageIndex == pageIndex && CurrentAnnotationLists[i].AnnotIndex == annotIndex)
  1097. {
  1098. CurrentAnnotationLists[i] = GetAddAnnotEventArgs(items[j]);
  1099. break;
  1100. }
  1101. }
  1102. await Task.Delay(5);//不加延时 每页的第一个注释不会展开
  1103. if (ViewContentViewModel.IsMultiSelected == false)
  1104. {
  1105. if (listBox.SelectedItems.IndexOf(AnnotationListItems[k]) == -1)
  1106. //if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
  1107. {
  1108. listBox.SelectedItem = AnnotationListItems[k];
  1109. //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  1110. }
  1111. }
  1112. ExpandGroupHeader(AnnotationListItems[k], listBox);
  1113. await Task.Delay(5);//不加延时 会有不滚动的现象
  1114. listBox.ScrollIntoView(AnnotationListItems[k]);
  1115. }
  1116. }
  1117. }
  1118. listBox.UpdateLayout();
  1119. //SetGroupHeader(listBox);
  1120. }
  1121. catch { }
  1122. }
  1123. /// <summary>
  1124. /// 展开item所在分组
  1125. /// </summary>
  1126. private void ExpandGroupHeader(AnnotationHandlerEventArgs item, ListBox listBox)
  1127. {
  1128. try
  1129. {
  1130. var groups = listBox.Items.Groups;
  1131. if (groups != null && groups.Count > 0)
  1132. {
  1133. for (int i = 0; i < groups.Count; i++)
  1134. {
  1135. var l = groups[i] as CollectionViewGroup;
  1136. if (l.Items.Contains(item))
  1137. {
  1138. var scroller = GetScrollHost(listBox);
  1139. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  1140. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  1141. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  1142. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  1143. if (g != null)
  1144. g.IsExpanded = true;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. catch { }
  1150. }
  1151. /// <summary>
  1152. /// 页面加载时
  1153. /// </summary>
  1154. /// <param name="obj"></param>
  1155. private void Loaded(object obj)
  1156. {
  1157. if (obj is CompositeCommandParameter composite)
  1158. {
  1159. if (composite.Parameter is ListBox listBox)
  1160. {
  1161. this.listBox = listBox;
  1162. //RefreshAnnotationListItems();
  1163. SetGroupHeader(listBox);
  1164. }
  1165. }
  1166. }
  1167. public bool IsNavigationTarget(NavigationContext navigationContext)
  1168. {
  1169. return true;
  1170. }
  1171. public void OnNavigatedFrom(NavigationContext navigationContext)
  1172. {
  1173. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1174. }
  1175. private ObservableCollection<AnnotationHandlerEventArgs> HideAnnots;
  1176. public void OnNavigatedTo(NavigationContext navigationContext)
  1177. {
  1178. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  1179. var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  1180. if (pdfview != null && viewContentViewModel != null)
  1181. {
  1182. ViewContentViewModel = viewContentViewModel;
  1183. PdfViewer = pdfview;
  1184. }
  1185. if (IsFirst)
  1186. {
  1187. IsFirst = false;
  1188. CurrentAnnotationLists = GetDocumentAnnotionList(out HideAnnots);
  1189. AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>();
  1190. AnnotationListItems.AddRange(CurrentAnnotationLists);
  1191. ICollectionView iCollectionView = CollectionViewSource.GetDefaultView(AnnotationListItems);
  1192. iCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotationHandlerEventArgs.PageIndex)));
  1193. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  1194. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  1195. //按照PageIndex,分组 排序
  1196. SetGroupHeader(listBox);
  1197. Screen = Visibility.Collapsed;
  1198. colors.Clear();
  1199. authors.Clear();
  1200. annotArgsTypes.Clear();
  1201. }
  1202. AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  1203. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1204. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1205. }
  1206. private void RefreshData(RefreshAnnotArgs obj)
  1207. {
  1208. if (obj.Annotation != null)
  1209. {
  1210. RefreshOneListItem(obj.Annotation.AnnotHandlerEventArgs);
  1211. }
  1212. }
  1213. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  1214. {
  1215. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  1216. {
  1217. if (listBox != null)
  1218. {
  1219. if (listBox.SelectedItems == null)
  1220. {
  1221. return;
  1222. }
  1223. listBox.SelectedItems.Clear();
  1224. }
  1225. }
  1226. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Delete))
  1227. {
  1228. if (listBox != null)
  1229. {
  1230. if (listBox.SelectedItems == null)
  1231. {
  1232. return;
  1233. }
  1234. List<int> pagelist = new List<int>();
  1235. for (int i = 0; i < listBox.SelectedItems.Count; i++)
  1236. {
  1237. AnnotationHandlerEventArgs annotation = listBox.SelectedItems[i] as AnnotationHandlerEventArgs;
  1238. pagelist.Add(listBox.Items.IndexOf(annotation));
  1239. }
  1240. pagelist.Sort();
  1241. for (int i = 0; i < pagelist.Count; i++)
  1242. {
  1243. AnnotationHandlerEventArgs annotation = listBox.Items[pagelist[pagelist.Count - i - 1]] as AnnotationHandlerEventArgs;
  1244. if (annotation == null)
  1245. {
  1246. continue;
  1247. }
  1248. DeleteCommand.Execute(annotation);
  1249. }
  1250. }
  1251. }
  1252. }
  1253. /// <summary>
  1254. /// 默认按照PageIndex,分组 排序
  1255. /// </summary>
  1256. /// <param name="listBox"></param>
  1257. private async void SetGroupHeader(ListBox listBox)
  1258. {
  1259. if (listBox == null) { return; }
  1260. #region BOTA,注释列表,添加在页面上的注释要默认按照页面上的位置排序,从上往下,从左往右排列
  1261. //AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>(AnnotationListItems.OrderBy(item => item.ClientRect.Y).ThenBy(item => item.ClientRect.X));
  1262. //CurrentAnnotationLists.AddRange(AnnotationListItems);
  1263. //AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  1264. //ICollectionView iCollectionView = CollectionViewSource.GetDefaultView(AnnotationListItems);
  1265. //iCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotationHandlerEventArgs.PageIndex)));
  1266. //iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  1267. ////iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  1268. //iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.ClientRect.Y), ListSortDirection.Ascending));
  1269. //iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.ClientRect.X), ListSortDirection.Ascending));
  1270. #endregion BOTA,注释列表,添加在页面上的注释要默认按照页面上的位置排序,从上往下,从左往右排列
  1271. if (AnnotationListItems == null)
  1272. {
  1273. return;
  1274. }
  1275. if (AnnotationListItems.Count > 0)
  1276. {
  1277. IsEmptyPanelVisibility = Visibility.Collapsed;
  1278. await Task.Delay(5);
  1279. //展开数据
  1280. ExpandGroupHeader(AnnotationListItems, listBox);
  1281. }
  1282. else
  1283. {
  1284. if (CurrentAnnotationLists.Count <= 0 && HideAnnots.Count > 1)
  1285. {
  1286. IsEmptyPanelVisibility = Visibility.Visible;
  1287. IsHideAnnotPanelVisibility = Visibility.Visible;
  1288. }
  1289. else
  1290. {
  1291. IsEmptyPanelVisibility = Visibility.Visible;
  1292. IsHideAnnotPanelVisibility = Visibility.Visible;
  1293. }
  1294. }
  1295. }
  1296. /// <summary>
  1297. /// 展开列表项
  1298. /// </summary>
  1299. /// <param name="annotationListItems"></param>
  1300. /// <param name="listBox"></param>
  1301. private void ExpandGroupHeader(ObservableCollection<AnnotationHandlerEventArgs> annotationListItems, ListBox listBox)
  1302. {
  1303. try
  1304. {
  1305. foreach (var item in annotationListItems)
  1306. {
  1307. var groups = listBox.Items.Groups;
  1308. for (int i = 0; i < groups.Count; i++)
  1309. {
  1310. var group = groups[i] as CollectionViewGroup;
  1311. if (group.Items.Contains(item))
  1312. {
  1313. var scroller = GetScrollHost(listBox);
  1314. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  1315. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  1316. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  1317. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  1318. if (g != null)
  1319. {
  1320. g.IsExpanded = true;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. }
  1326. catch { }
  1327. }
  1328. private ScrollViewer GetScrollHost(ListBox listBox)
  1329. {
  1330. if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
  1331. {
  1332. int s = VisualTreeHelper.GetChildrenCount(listBox);
  1333. Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
  1334. if (border != null)
  1335. {
  1336. return VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
  1337. }
  1338. }
  1339. return null;
  1340. }
  1341. /// <summary>
  1342. /// 获取listbox绑定数据
  1343. /// </summary>
  1344. /// <returns></returns>
  1345. public ObservableCollection<AnnotationHandlerEventArgs> GetDocumentAnnotionList(out ObservableCollection<AnnotationHandlerEventArgs> HideAnnots)
  1346. {
  1347. ObservableCollection<AnnotationHandlerEventArgs> list = new ObservableCollection<AnnotationHandlerEventArgs>();
  1348. HideAnnots = new ObservableCollection<AnnotationHandlerEventArgs>();
  1349. for (int i = 0; i < PdfViewer.Document.PageCount; i++)
  1350. {
  1351. var items = PdfViewer.GetAnnotCommentList(i, PdfViewer.Document);
  1352. foreach (var item in items)
  1353. {
  1354. //原型图上,目前对波浪线的类型,在注释列表不显示
  1355. //注释列表 不显示链接注释
  1356. if (item.EventType != AnnotArgsType.AnnotRedaction && item.EventType != AnnotArgsType.AnnotSquiggly
  1357. && item.EventType != AnnotArgsType.AnnotLink)
  1358. {
  1359. if (item.EventType == AnnotArgsType.AnnotLink)
  1360. {
  1361. if (item is LinkAnnotArgs link)
  1362. {
  1363. if (link.LinkType == LINK_TYPE.URI)
  1364. {
  1365. continue;
  1366. }
  1367. }
  1368. }
  1369. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  1370. bool isVisible = PdfViewer.CheckAnnotVisible(args.PageIndex, args.AnnotIndex);
  1371. if (args.AnnotHandlerEventArgs != null)
  1372. {
  1373. if (isVisible)
  1374. {
  1375. list.Add(args);
  1376. }
  1377. else
  1378. {
  1379. HideAnnots.Add(args);
  1380. }
  1381. }
  1382. }
  1383. }
  1384. }
  1385. return list;
  1386. }
  1387. public AnnotationHandlerEventArgs GetAddAnnotEventArgs(AnnotHandlerEventArgs item)
  1388. {
  1389. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1390. if (item.EventType == AnnotArgsType.AnnotFreehand)
  1391. {
  1392. BitmapImage bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
  1393. if (bitmap != null)
  1394. args.WriteableBitmap = bitmap;
  1395. }
  1396. args.ClientRect = item.ClientRect;
  1397. args.AnnotHandlerEventArgs = item;
  1398. args.PageIndex = item.PageIndex;
  1399. args.AnnotIndex = item.AnnotIndex;
  1400. args.EventType = item.EventType;
  1401. args.CreateTime = item.CreateTime;
  1402. args.UpdateTime = item.UpdateTime;
  1403. args.Content = item.Content;
  1404. args.MarkupContent = item.MarkupContent;
  1405. args.Author = item.Author;
  1406. args.Locked = item.Locked;
  1407. args.ReadOnly = item.ReadOnly;
  1408. args.FormField = item.FormField;
  1409. args.Document = PdfViewer.Document;
  1410. return args;
  1411. }
  1412. /// <summary>
  1413. /// 获取手绘图案
  1414. /// </summary>
  1415. /// <param name="doc"></param>
  1416. /// <param name="pageIndex"></param>
  1417. /// <param name="annotIndex"></param>
  1418. /// <returns></returns>
  1419. public BitmapImage GetAnnotImage(CPDFDocument doc, int pageIndex, int annotIndex)
  1420. {
  1421. if (doc == null)
  1422. {
  1423. return null;
  1424. }
  1425. CPDFPage docPage = doc.PageAtIndex(pageIndex, false);
  1426. if (docPage == null)
  1427. {
  1428. return null;
  1429. }
  1430. List<CPDFAnnotation> docAnnots = docPage.GetAnnotations();
  1431. foreach (CPDFAnnotation annot in docAnnots)
  1432. {
  1433. if (docAnnots.IndexOf(annot) == annotIndex)
  1434. {
  1435. CPDFInkAnnotation cPDFInk = (CPDFInkAnnotation)docAnnots[annotIndex];
  1436. //CRect rawRect = annot.GetRect();
  1437. CRect rawRect = cPDFInk.Rect;
  1438. double scaleDpi = 96.0 / 72.0;
  1439. Rect paintRect = new Rect(rawRect.left * scaleDpi, rawRect.top * scaleDpi, rawRect.width() * scaleDpi, rawRect.height() * scaleDpi);
  1440. int drawWidth = (int)paintRect.Width;
  1441. int drawHeight = (int)paintRect.Height;
  1442. switch (docPage.Rotation)
  1443. {
  1444. case 0:
  1445. case 2:
  1446. drawWidth = (int)paintRect.Width;
  1447. drawHeight = (int)paintRect.Height;
  1448. break;
  1449. case 1:
  1450. case 3:
  1451. drawWidth = (int)paintRect.Height;
  1452. drawHeight = (int)paintRect.Width;
  1453. break;
  1454. }
  1455. byte[] bitmapArray = new byte[drawWidth * drawHeight * 4];
  1456. annot.UpdateAp();
  1457. annot.RenderAnnot(drawWidth, drawHeight, bitmapArray);
  1458. BitmapImage bitmapImage = null;
  1459. if (drawWidth != 0 && drawHeight != 0)
  1460. {
  1461. WriteableBitmap wirteBitmap = new WriteableBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Bgra32, null);
  1462. wirteBitmap.WritePixels(new Int32Rect(0, 0, drawWidth, drawHeight), bitmapArray, wirteBitmap.BackBufferStride, 0);
  1463. bitmapImage = ConvertWriteableBitmapToBitmapImage(wirteBitmap, docPage.Rotation);
  1464. }
  1465. else
  1466. {
  1467. bitmapImage = null;
  1468. }
  1469. cPDFInk.SetRect(rawRect);
  1470. // 测试
  1471. //using (FileStream stream = new FileStream(@"C:\Users\oyxh\Desktop\images\1.png", FileMode.Create))
  1472. //{
  1473. // PngBitmapEncoder bitmapEncoder = new PngBitmapEncoder();
  1474. // bitmapEncoder.Frames.Add(BitmapFrame.Create(wirteBitmap));
  1475. // bitmapEncoder.Save(stream);
  1476. //}
  1477. return bitmapImage;
  1478. }
  1479. }
  1480. return null;
  1481. }
  1482. public BitmapImage ConvertWriteableBitmapToBitmapImage(WriteableBitmap wbm, int rotation)
  1483. {
  1484. BitmapImage bmImage = new BitmapImage();
  1485. using (MemoryStream stream = new MemoryStream())
  1486. {
  1487. PngBitmapEncoder encoder = new PngBitmapEncoder();
  1488. encoder.Frames.Add(BitmapFrame.Create(wbm));
  1489. encoder.Save(stream);
  1490. bmImage.BeginInit();
  1491. bmImage.CacheOption = BitmapCacheOption.OnLoad;
  1492. bmImage.StreamSource = stream;
  1493. switch (rotation)
  1494. {
  1495. case 0:
  1496. bmImage.Rotation = Rotation.Rotate0;
  1497. break;
  1498. case 1:
  1499. bmImage.Rotation = Rotation.Rotate90;
  1500. break;
  1501. case 2:
  1502. bmImage.Rotation = Rotation.Rotate180;
  1503. break;
  1504. case 3:
  1505. bmImage.Rotation = Rotation.Rotate270;
  1506. break;
  1507. }
  1508. bmImage.EndInit();
  1509. bmImage.Freeze();
  1510. }
  1511. return bmImage;
  1512. }
  1513. /// <summary>
  1514. /// listbox的itemsource发生变化时
  1515. /// </summary>
  1516. /// <param name="sender"></param>
  1517. /// <param name="e"></param>
  1518. private void AnnotationListItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  1519. {
  1520. if (sender is ObservableCollection<AnnotationHandlerEventArgs> obsSender)
  1521. {
  1522. //currentAnnotationArgs.Clear();
  1523. //currentAnnotationArgs.AddRange(obsSender);
  1524. if (obsSender.Count < 1)
  1525. {
  1526. if (CurrentAnnotationLists.Count <= 0)
  1527. {
  1528. IsHideAnnotPanelVisibility = Visibility.Collapsed;
  1529. IsEmptyPanelVisibility = Visibility.Visible;
  1530. }
  1531. else
  1532. {
  1533. if (isHiddenAnnot)
  1534. {
  1535. IsHideAnnotPanelVisibility = Visibility.Collapsed;
  1536. IsEmptyPanelVisibility = Visibility.Visible;
  1537. }
  1538. else
  1539. {
  1540. IsEmptyPanelVisibility = Visibility.Visible;
  1541. IsHideAnnotPanelVisibility = Visibility.Visible;
  1542. }
  1543. }
  1544. //IsEmptyPanelVisibility = Visibility.Visible;
  1545. }
  1546. else
  1547. {
  1548. IsEmptyPanelVisibility = Visibility.Collapsed;
  1549. IsHideAnnotPanelVisibility = Visibility.Collapsed;
  1550. }
  1551. }
  1552. else
  1553. {
  1554. IsEmptyPanelVisibility = Visibility.Visible;
  1555. }
  1556. }
  1557. }
  1558. }