AnnotationContentViewModel.cs 71 KB

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