AnnotationContentViewModel.cs 48 KB

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