AnnotToolContentViewModel.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using ImTools;
  7. using Microsoft.Win32;
  8. using PDF_Master.CustomControl;
  9. using PDF_Master.EventAggregators;
  10. using PDF_Master.Helper;
  11. using PDF_Master.Model;
  12. using PDF_Master.Model.BOTA;
  13. using PDF_Master.Properties;
  14. using PDF_Master.ViewModels.BOTA;
  15. using PDF_Master.ViewModels.PropertyPanel;
  16. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  17. using PDF_Master.ViewModels.Tools.AnnotManager;
  18. using PDF_Master.Views.BOTA;
  19. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  20. using PDFSettings;
  21. using PDFSettings.Settings;
  22. using Prism.Commands;
  23. using Prism.Events;
  24. using Prism.Mvvm;
  25. using Prism.Regions;
  26. using Prism.Services.Dialogs;
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Linq;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Windows;
  35. using System.Windows.Annotations;
  36. using System.Windows.Controls;
  37. using System.Windows.Controls.Primitives;
  38. using System.Windows.Forms;
  39. using System.Windows.Input;
  40. using System.Windows.Media;
  41. using System.Windows.Media.Imaging;
  42. using ContextMenu = System.Windows.Controls.ContextMenu;
  43. using KeyEventArgs = System.Windows.Input.KeyEventArgs;
  44. using MenuItem = System.Windows.Controls.MenuItem;
  45. namespace PDF_Master.ViewModels.Tools
  46. {
  47. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  48. {
  49. #region 初始化
  50. public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService)
  51. {
  52. region = regionManager;
  53. events = eventAggregator;
  54. dialogs = dialogService;
  55. InitCommand();
  56. InitDefaultValue();
  57. InitToolDict();
  58. InitToolTipDict();
  59. InitPopMenu();
  60. SubscribeEvent();
  61. AnnotContainerBorderColor();
  62. }
  63. //注释容器选中边框的颜色
  64. private void AnnotContainerBorderColor()
  65. {
  66. var pen = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4)), 1);
  67. CommonDrawData.ActiveBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4));
  68. CommonDrawData.ActivePen = pen;
  69. }
  70. //事件聚合器
  71. private void SubscribeEvent()
  72. {
  73. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  74. events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
  75. }
  76. private void InitPopMenu()
  77. {
  78. InitSelectHightAnnotMenu();
  79. InitSelectFreeHandAnnotMenu();
  80. InitSelectFreeTextAnnotMenu();
  81. InitSelectStrickNoteAnnotMenu();
  82. InitSelectShapeAnnotMenu();
  83. InitSelectLinkAnnotMenu();
  84. InitSelectStampAnnotMenu();
  85. InitSelectMultiAnnotMenu();
  86. }
  87. private void InitCommand()
  88. {
  89. MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
  90. SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
  91. AddBookMarkCommand = new DelegateCommand(AddBookMark_Click);
  92. PropertyRegionName = Guid.NewGuid().ToString();
  93. HandCommand = new DelegateCommand(Hand_Click);
  94. #region 注释 - 右键菜单
  95. //公共command
  96. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  97. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  98. AnnotAddNoteText_MenuCommand = new DelegateCommand<object>(AnnotAddNoteText_Menu);
  99. //高亮、下划线、删除
  100. HightAnnotCopyText_MenuCommand = new DelegateCommand<object>(HightAnnotCopyText_Menu);
  101. //手绘
  102. FreeHandLineStyle_MenuCommand = new DelegateCommand<object>(FreeHandLineStyle_Menu);
  103. //文本
  104. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  105. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  106. //便签
  107. StrikeNoteEditStrike_MenuCommand = new DelegateCommand<object>(StrikeNoteEditStrike_Menu);
  108. //形状
  109. ShapeLineStyle_MenuCommand = new DelegateCommand<object>(ShapeLineStyle_Menu);
  110. ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
  111. //图章
  112. StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
  113. //链接
  114. Link_MenuCommand = new DelegateCommand<object>(Link_Menu);
  115. #endregion 注释 - 右键菜单
  116. }
  117. #endregion 初始化
  118. #region 注释工具栏 -》Command实现
  119. //手型工具
  120. private void Hand_Click()
  121. {
  122. HandToolIsCheckedEvent(BtnHandIsChecked);
  123. if (BtnHandIsChecked)
  124. {
  125. //其余注释工具 取消选中
  126. StrAnnotToolChecked = "";
  127. BtnLinkIsChecked = false;
  128. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  129. }
  130. }
  131. //手型工具按钮选中或取消
  132. private void HandToolIsCheckedEvent(bool isChecked)
  133. {
  134. if (isChecked == false)
  135. {
  136. //鼠标框选多选注释
  137. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  138. {
  139. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  140. var annotArgs = new SelectToolArgs();
  141. PDFViewer.SetToolParam(annotArgs);
  142. }
  143. else
  144. {
  145. PDFViewer.SetMouseMode(MouseModes.PanTool);
  146. }
  147. }
  148. else
  149. {
  150. //鼠标滚动页面
  151. PDFViewer.SetMouseMode(MouseModes.Scroll);
  152. PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
  153. }
  154. }
  155. //点击注释工具
  156. private void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
  157. {
  158. if (annotBtn == null || annotBtn.Tag == null) return;
  159. //不创建注释,属于注释模板
  160. Dictionary<string, bool> dictVar = new Dictionary<string, bool>();
  161. dictVar.Add("isTemplateAnnot", false);
  162. dictVar.Add("isSnapshotEdit", false);
  163. AnnotHandlerEventArgs annotArgs = null;
  164. var tag = annotBtn.Tag.ToString();
  165. if (annotBtn.Name == "BtnShowAnnot")
  166. {
  167. //显示/隐藏注释
  168. PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
  169. return;
  170. }
  171. if (annotBtn.IsChecked == true)
  172. {
  173. propertyPanel.SaveLastAnnot();
  174. MyToolCheckedDoing(dictVar, tag);
  175. FindAnnotTypeKey(tag, ref annotArgs);
  176. if (annotArgs != null)
  177. {
  178. //设置点击页面会创建对应选中注释工具的注释
  179. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  180. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  181. PDFViewer.SetToolParam(annotArgs);
  182. }
  183. }
  184. else
  185. {
  186. //取消选中注释工具按钮后,恢复到未编辑注释的状态
  187. propertyPanel.IsAddLink = false;
  188. propertyPanel.IsLocationLink = false;
  189. PDFViewer.ToolManager.EnableClickCreate = false;
  190. PDFViewer.SetMouseMode(MouseModes.PanTool);
  191. ShowPropertyPanel(false);
  192. }
  193. if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
  194. {
  195. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  196. HandToolIsCheckedEvent(false);
  197. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  198. }
  199. else
  200. {
  201. if (dictVar["isSnapshotEdit"] == true)
  202. {
  203. ShowPropertyPanel(false);
  204. }
  205. else
  206. {
  207. ShowPropertyPanel((bool)annotBtn.IsChecked);
  208. }
  209. }
  210. }
  211. //选中注释工具按钮时,处理的一些系列事情
  212. private void MyToolCheckedDoing(Dictionary<string, bool> dict, string tag)
  213. {
  214. if (BtnHandIsChecked)
  215. BtnHandIsChecked = false;
  216. PDFViewer.ClearSelectAnnots();
  217. //选中内容选择工具按钮
  218. if (tag == "SnapshotEdit")
  219. {
  220. dict["isSnapshotEdit"] = true;
  221. }
  222. else if (tag == "Signature" || tag == "Stamp")
  223. {
  224. //选中签名、图章工具按钮
  225. dict["isTemplateAnnot"] = true;
  226. }
  227. //超链接工具
  228. //if (tag != "Link")
  229. // BtnLinkIsChecked = false;
  230. //else
  231. // StrAnnotToolChecked = "Link";
  232. if (tag != "Link")
  233. {
  234. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  235. //if (region.Regions.ContainsRegionWithName(viewContentViewModel.TipContentRegionName))
  236. //{
  237. // var views = region.Regions[viewContentViewModel.TipContentRegionName].Views;
  238. // Views.TipContent.LinkAnnotTip isHas = (Views.TipContent.LinkAnnotTip)views.FindFirst(q => q is Views.TipContent.LinkAnnotTip);
  239. // if (isHas != null)
  240. // {
  241. // viewContentViewModel.TipVisible = System.Windows.Visibility.Collapsed;
  242. // (isHas.DataContext as LinkAnnotPropertyViewModel).BtnLocationIsChecked = false;
  243. // }
  244. //}
  245. }
  246. if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
  247. {
  248. //新建形状注释,设置默认大小
  249. PDFViewer.ToolManager.EnableClickCreate = true;
  250. PDFViewer.ToolManager.ClickCreateWidth = 140;
  251. PDFViewer.ToolManager.ClickCreateHeight = 140;
  252. }
  253. else
  254. {
  255. PDFViewer.ToolManager.EnableClickCreate = false;
  256. }
  257. }
  258. #endregion 注释工具栏 -》Command实现
  259. #region BOTA
  260. private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
  261. {
  262. AnnotationContentViewModel viewModel = null;
  263. annotation = null;
  264. if (bOTAContentViewModel != null)
  265. {
  266. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  267. {
  268. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  269. foreach (var item in views)
  270. {
  271. if (item is AnnotationContent annotation1)
  272. {
  273. annotation = annotation1;
  274. viewModel = annotation1.DataContext as AnnotationContentViewModel;
  275. break;
  276. }
  277. }
  278. }
  279. }
  280. return viewModel;
  281. }
  282. /// <summary>
  283. /// 判断Bota的TabItem是否已显示
  284. /// </summary>
  285. /// <param name="bOTAContentViewModel"></param>
  286. /// <param name="bOTAContent"></param>
  287. /// <param name="tabItemText"></param>
  288. /// <returns></returns>
  289. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  290. {
  291. bool isTabItem = false;
  292. bOTAContentViewModel = null;
  293. bOTAContent = null;
  294. if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  295. {
  296. var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
  297. var model = views.FirstOrDefault(q => q is BOTAContent);
  298. if (model is BOTAContent bOTAContent1)
  299. {
  300. bOTAContent = bOTAContent1;
  301. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  302. if (bOTAContentViewModel.CurrentBar == tabItemText)
  303. {
  304. isTabItem = true;
  305. }
  306. }
  307. }
  308. return isTabItem;
  309. }
  310. private void Select_Click(object sender, RoutedEventArgs e)
  311. {
  312. if (viewContentViewModel.OpenBOTA == false)
  313. {
  314. viewContentViewModel.OpenBOTA = true;
  315. }
  316. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  317. if (isBook == false)
  318. {
  319. bOTAContent.TabItemSearch.IsSelected = true;
  320. }
  321. }
  322. #endregion BOTA
  323. #region 阅读页右键菜单
  324. /// <summary>
  325. /// 空白处-右键菜单-添加注释
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. private void AddAnnotation_Click(object sender)
  329. {
  330. if (sender is MenuItem menuItem)
  331. {
  332. AnnotHandlerEventArgs annotHandler = null;
  333. string str = menuItem.Tag.ToString();
  334. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  335. propertyPanel.IsAddLink = false;
  336. propertyPanel.IsLocationLink = false;
  337. if (str == AddAnnotType.AnnotFreehand.ToString())
  338. {
  339. annotHandler = GetFreehand();
  340. }
  341. if (str == AddAnnotType.AnnotFreeText.ToString())
  342. {
  343. annotHandler = GetFreetext();
  344. }
  345. if (str == AddAnnotType.AnnotSticky.ToString())
  346. {
  347. annotHandler = GetStickyNote();
  348. }
  349. if (str == AddAnnotType.AnnotSquare.ToString())
  350. {
  351. annotHandler = GetRect();
  352. }
  353. if (str == AddAnnotType.AnnotCircle.ToString())
  354. {
  355. annotHandler = GetCircle();
  356. }
  357. if (str == AddAnnotType.AnnotArrow.ToString())
  358. {
  359. annotHandler = GetArrowLine("Arrow");
  360. }
  361. if (str == AddAnnotType.AnnotLine.ToString())
  362. {
  363. annotHandler = GetArrowLine("Line");
  364. }
  365. if (str == AddAnnotType.AnnotLink.ToString())
  366. {
  367. propertyPanel.IsAddLink = true;
  368. annotHandler = GetLink();
  369. }
  370. if (str == AddAnnotType.AnnotStamp.ToString())
  371. {
  372. annotHandler = GetStamp();
  373. }
  374. if (str == AddAnnotType.AnnotAutograph.ToString())
  375. {
  376. annotHandler = GetSignature();
  377. }
  378. if (annotHandler != null)
  379. {
  380. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  381. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  382. PDFViewer.SetToolParam(annotHandler);
  383. //是否展开右侧面板 =>否(链接、图章、签名除外)
  384. ShowPropertyPanel(false);
  385. if (str == AddAnnotType.AnnotLink.ToString()
  386. || str == AddAnnotType.AnnotStamp.ToString()
  387. || str == AddAnnotType.AnnotAutograph.ToString()
  388. )
  389. {
  390. ShowPropertyPanel(true);
  391. }
  392. IsNoSelectMenu = true;
  393. }
  394. }
  395. }
  396. /// <summary>
  397. /// 选择文本、图片,右键菜单
  398. /// </summary>
  399. /// <param name="sender"></param>
  400. /// <param name="e"></param>
  401. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  402. {
  403. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  404. {
  405. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  406. switch (clickMenu.Tag.ToString())
  407. {
  408. case "HighLight"://字体高亮
  409. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  410. highlightArgs.ClientRect = annotCommand.TextRect;
  411. highlightArgs.Content = annotCommand.Text;
  412. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  413. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  414. PDFViewer.SetToolParam(highlightArgs);
  415. PDFViewer.SetMouseMode(MouseModes.PanTool);
  416. break;
  417. case "UnderLine"://下划线
  418. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  419. underlineArgs.ClientRect = annotCommand.TextRect;
  420. underlineArgs.Content = annotCommand.Text;
  421. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  422. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  423. PDFViewer.SetToolParam(underlineArgs);
  424. PDFViewer.SetMouseMode(MouseModes.PanTool);
  425. break;
  426. case "Strikeout"://删除线
  427. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  428. strikeoutArgs.ClientRect = annotCommand.TextRect;
  429. strikeoutArgs.Content = annotCommand.Text;
  430. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  431. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  432. PDFViewer.SetToolParam(strikeoutArgs);
  433. PDFViewer.SetMouseMode(MouseModes.PanTool);
  434. break;
  435. case "Freetext"://文本
  436. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  437. textArgs.ClientRect = annotCommand.TextRect;
  438. //textArgs.Transparency = 1;
  439. //textArgs.BgColor = Colors.Transparent;
  440. //textArgs.LineColor = Colors.Red;
  441. //textArgs.LineWidth = 2;
  442. textArgs.TextContent = annotCommand.Text;
  443. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  444. break;
  445. case "StickyNote"://便签
  446. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  447. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  448. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  449. //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  450. Rect rect = annotCommand.TextRectList[0];
  451. #region to do 转dpi
  452. //int dpi = DpiHelpers.Dpi;
  453. //double x = rect.X / 72D * dpi;
  454. //double y = (rect.Y - rect.Height) / 72D * dpi;
  455. //double width = rect.Width / 72D * dpi;
  456. //double height = rect.Height / 72D * dpi;
  457. #endregion to do 转dpi
  458. //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
  459. //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
  460. stickyAnnotArgs.ClientRect = rect;
  461. //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  462. NavigationParameters param = new NavigationParameters();
  463. param.Add(ParameterNames.PDFViewer, PDFViewer);
  464. param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
  465. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  466. param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
  467. System.Windows.Controls.ContentControl window = null;
  468. if (PDFViewer.Parent as ContentControl != null)
  469. {
  470. window = PDFViewer.Parent as ContentControl;
  471. }
  472. else
  473. {
  474. window = App.Current.MainWindow;
  475. }
  476. var point = Mouse.GetPosition(window);
  477. viewContentViewModel.NotePopupVisible = Visibility.Visible;
  478. viewContentViewModel.CanvasNoteLeft = point.X;
  479. viewContentViewModel.CanvasNoteBottom = point.Y;
  480. if (point.Y > window.ActualHeight / 2)
  481. {
  482. viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
  483. }
  484. viewContentViewModel.IsNoteAdd = true;
  485. region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
  486. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  487. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  488. //PDFViewer.SetToolParam(stickyAnnotArgs);
  489. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  490. break;
  491. case "Rect"://矩形
  492. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  493. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  494. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  495. break;
  496. case "Circle"://圆
  497. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  498. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  499. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  500. break;
  501. case "Line"://线
  502. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  503. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  504. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  505. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  506. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  507. break;
  508. case "Link"://链接
  509. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  510. linkArgs.ClientRect = annotCommand.TextRect;
  511. linkArgs.URI = string.Empty;
  512. linkArgs.LinkType = LINK_TYPE.GOTO;
  513. linkArgs.DestIndex = annotCommand.PageIndex;
  514. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  515. //BtnLinkIsChecked = true;
  516. StrAnnotToolChecked = "Link";
  517. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  518. lists.Add(linkArgs);
  519. propertyPanel.IsAddLink = true;
  520. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  521. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  522. PDFViewer.SetToolParam(annotArgs);
  523. viewContentViewModel.IsPropertyOpen = true;
  524. break;
  525. case "OutLine":
  526. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  527. if (isTabItemAnnotation == false)
  528. {
  529. bOTAContent.TabItemOutLine.IsSelected = true;
  530. }
  531. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  532. if (outLineControlViewModel != null && outLineControl != null)
  533. {
  534. string str = null;
  535. if (!string.IsNullOrEmpty(annotCommand.Text))
  536. {
  537. str = annotCommand.Text;
  538. }
  539. #region 选择图片
  540. //if (string.IsNullOrEmpty(annotCommand.Text))
  541. //{
  542. // str = (annotCommand.PageIndex + 1).ToString();
  543. //}
  544. //else
  545. //{
  546. // str = annotCommand.Text;
  547. //}
  548. #endregion 选择图片
  549. outLineControl.AddOutlineNode(str);
  550. }
  551. break;
  552. case "ExportPicture":
  553. ExportPicture_MenuItemClick();
  554. break;
  555. }
  556. //ShowPropertyPanel(false);
  557. }
  558. }
  559. private void PageDisplay(ItemCollection items)
  560. {
  561. foreach (var item in items)
  562. {
  563. if (item is MenuItem menuItem)
  564. {
  565. menuItem.IsCheckable = false;
  566. menuItem.Click -= PageDisplay_Click;
  567. menuItem.Click += PageDisplay_Click;
  568. }
  569. }
  570. }
  571. private void PageDisplay_Click(object sender, RoutedEventArgs e)
  572. {
  573. if (sender is MenuItem menuItem)
  574. {
  575. switch (menuItem.Tag.ToString())
  576. {
  577. case "SingleView":
  578. PDFViewer.ChangeViewMode(ViewMode.Single);
  579. break;
  580. case "SingleContinueView":
  581. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  582. break;
  583. case "DoubleView":
  584. PDFViewer.ChangeViewMode(ViewMode.Double);
  585. break;
  586. case "DoubleContinueView":
  587. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  588. break;
  589. case "BookMode":
  590. PDFViewer.ChangeViewMode(ViewMode.Book);
  591. break;
  592. }
  593. }
  594. }
  595. private void ViewZoom(ItemCollection items)
  596. {
  597. foreach (var item in items)
  598. {
  599. if (item is MenuItem menuItem)
  600. {
  601. //switch (PDFViewer.ModeFit)
  602. //{
  603. // case FitMode.FitWidth:
  604. // break;
  605. // case FitMode.FitHeight:
  606. // break;
  607. // case FitMode.FitSize:
  608. // break;
  609. // case FitMode.FitFree:
  610. // break;
  611. // default:
  612. // break;
  613. //}
  614. menuItem.IsCheckable = false;
  615. menuItem.Click -= ViewZoom_Click;
  616. menuItem.Click += ViewZoom_Click;
  617. }
  618. }
  619. }
  620. private void ViewZoom_Click(object sender, RoutedEventArgs e)
  621. {
  622. if (sender is MenuItem menuItem)
  623. {
  624. switch (menuItem.Tag.ToString())
  625. {
  626. case "FitWidth":
  627. PDFViewer.ChangeFitMode(FitMode.FitWidth);
  628. break;
  629. case "FitHeight":
  630. PDFViewer.ChangeFitMode(FitMode.FitHeight);
  631. break;
  632. case "FitSize":
  633. PDFViewer.ChangeFitMode(FitMode.FitSize);
  634. break;
  635. case "enlarge":
  636. double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
  637. PDFViewer.Zoom(newZoom);
  638. break;
  639. case "narrow":
  640. newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
  641. PDFViewer.Zoom(newZoom);
  642. break;
  643. }
  644. }
  645. }
  646. private void UnReadModel_Click(object sender, RoutedEventArgs e)
  647. {
  648. viewContentViewModel.Off_ReadModel();
  649. }
  650. private void ReadModel_Click(object sender, RoutedEventArgs e)
  651. {
  652. viewContentViewModel.On_ReadMode();
  653. }
  654. private void SetToolMode(ItemCollection items)
  655. {
  656. foreach (var item in items)
  657. {
  658. if (item is MenuItem menuItem)
  659. {
  660. menuItem.IsCheckable = false;
  661. menuItem.Click -= ToolMode_Click;
  662. menuItem.Click += ToolMode_Click;
  663. }
  664. }
  665. }
  666. private void ToolMode_Click(object sender, RoutedEventArgs e)
  667. {
  668. if (sender is MenuItem menuItem)
  669. {
  670. switch (menuItem.Tag.ToString())
  671. {
  672. case "default":
  673. HandToolIsCheckedEvent(false);
  674. BtnHandIsChecked = false;
  675. ShowPropertyPanel(false);
  676. break;
  677. case "roll":
  678. HandToolIsCheckedEvent(true);
  679. BtnHandIsChecked = true;
  680. ShowPropertyPanel(false);
  681. break;
  682. case "content":
  683. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  684. BtnSelecttoolIsChecked = true;
  685. if (annotHandler != null)
  686. {
  687. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  688. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  689. PDFViewer.SetToolParam(annotHandler);
  690. ShowPropertyPanel(false);
  691. }
  692. break;
  693. default:
  694. break;
  695. }
  696. }
  697. }
  698. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  699. {
  700. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  701. if (bOTAContentVM != null && bOTA != null)
  702. {
  703. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  704. int index = PDFViewer.CurrentIndex;
  705. //检测是否已存在相同数据
  706. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  707. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  708. {
  709. bookmarkContentViewModel.DeleteCommand.Execute(list);
  710. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  711. }
  712. }
  713. }
  714. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  715. {
  716. if (viewContentViewModel.OpenBOTA == false)
  717. {
  718. viewContentViewModel.OpenBOTA = true;
  719. }
  720. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  721. if (isBook == false)
  722. {
  723. bOTA.TabItemBookMark.IsSelected = true;
  724. }
  725. }
  726. private void AddBookMark_Click()
  727. {
  728. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  729. //if (viewContentViewModel.mainViewModel.IsBookMode)
  730. //{
  731. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  732. //}
  733. if (bOTAContentVM != null && bOTA != null)
  734. {
  735. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  736. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  737. {
  738. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  739. bookmark.BtnAddBookmark_Click(null, null);
  740. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  741. return;
  742. }
  743. }
  744. }
  745. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  746. {
  747. BookmarkContentViewModel viewModel = null;
  748. bookmark = null;
  749. if (bOTAContentViewModel != null)
  750. {
  751. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  752. {
  753. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  754. foreach (var item in views)
  755. {
  756. if (item is BookmarkContent bookmark1)
  757. {
  758. bookmark = bookmark1;
  759. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  760. break;
  761. }
  762. }
  763. }
  764. }
  765. return viewModel;
  766. }
  767. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  768. {
  769. OutLineControlViewModel viewModel = null;
  770. outLineControl = null;
  771. if (bOTAContentViewModel != null)
  772. {
  773. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  774. {
  775. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  776. foreach (var item in views)
  777. {
  778. if (item is OutLineControl outLineControl1)
  779. {
  780. outLineControl = outLineControl1;
  781. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  782. break;
  783. }
  784. }
  785. }
  786. }
  787. return viewModel;
  788. }
  789. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  790. {
  791. PDFViewer.SetDrawAnnot(true);
  792. BtnShowAnnotIsChecked = true;
  793. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  794. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  795. {
  796. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  797. viewModel.DisplayAnnot();
  798. }
  799. }
  800. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  801. {
  802. PDFViewer.SetDrawAnnot(false);
  803. BtnShowAnnotIsChecked = false;
  804. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  805. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  806. {
  807. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  808. viewModel.HiddenAnnot();
  809. }
  810. }
  811. private void SetAddAnnotation(ItemCollection items)
  812. {
  813. foreach (var item in items)
  814. {
  815. if (item is MenuItem menuItem)
  816. {
  817. string str = menuItem.Tag.ToString();
  818. //if (str == AddAnnotType.AnnotLink.ToString()
  819. //|| str == AddAnnotType.AnnotStamp.ToString()
  820. //|| str == AddAnnotType.AnnotAutograph.ToString()
  821. //)
  822. //{
  823. // InBookModeSetIsEnabled(menuItem);
  824. //}
  825. menuItem.CommandParameter = item;
  826. menuItem.Command = SetAddAnnotationCommand;
  827. }
  828. }
  829. }
  830. //private void AddLink_Click(object sender, RoutedEventArgs e)
  831. //{
  832. // var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  833. // BtnLinkIsChecked = true;
  834. //}
  835. #endregion 阅读页右键菜单
  836. #region 注释右键菜单事件
  837. //高亮、下划线、删除
  838. private void HightAnnotCopyText_Menu(object obj)
  839. {
  840. if (obj as CusMenuItem != null)
  841. {
  842. var menu = obj as CusMenuItem;
  843. var annot = menu.Parameter as AnnotHandlerEventArgs;
  844. if (annot != null)
  845. {
  846. System.Windows.Clipboard.SetText(annot.Content);
  847. }
  848. }
  849. }
  850. //更改为当前注释属性默认值
  851. private void AnnotDefaultValues_Menu(object obj)
  852. {
  853. if (obj as CusMenuItem != null)
  854. {
  855. var menu = obj as CusMenuItem;
  856. var annot = menu.Parameter as AnnotHandlerEventArgs;
  857. if (annot != null)
  858. {
  859. if (annot is TextHighlightAnnotArgs)
  860. {
  861. var color = (annot as TextHighlightAnnotArgs).Color;
  862. HighLightColor = new SolidColorBrush(color);
  863. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  864. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  865. hightlight.ForgoundColor = color;
  866. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  867. SettingHelper.SetAnnotDefaultProperty(hightlight);
  868. }
  869. else if (annot is TextUnderlineAnnotArgs)
  870. {
  871. var color = (annot as TextUnderlineAnnotArgs).Color;
  872. UnderLineColor = new SolidColorBrush(color);
  873. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  874. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  875. Underline.ForgoundColor = color;
  876. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  877. SettingHelper.SetAnnotDefaultProperty(Underline);
  878. }
  879. else if (annot is TextStrikeoutAnnotArgs)
  880. {
  881. var color = (annot as TextStrikeoutAnnotArgs).Color;
  882. StrikeoutColor = new SolidColorBrush(color);
  883. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  884. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  885. Strikeout.ForgoundColor = color;
  886. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  887. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  888. }
  889. else if (annot is FreehandAnnotArgs)
  890. {
  891. var freeHand = annot as FreehandAnnotArgs;
  892. var color = freeHand.InkColor;
  893. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  894. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  895. FreehandDefault.ForgoundColor = color;
  896. FreehandDefault.Opacity = freeHand.Transparency;
  897. FreehandDefault.Thickness = freeHand.LineWidth;
  898. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  899. if (isSolid)
  900. {
  901. FreehandDefault.DashArray = null;
  902. }
  903. else
  904. {
  905. FreehandDefault.DashArray = new List<double>();
  906. foreach (var item in freeHand.LineDash.Dashes)
  907. {
  908. FreehandDefault.DashArray.Add(item);
  909. }
  910. }
  911. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  912. }
  913. else if (annot is FreeTextAnnotArgs)
  914. {
  915. var freeText = annot as FreeTextAnnotArgs;
  916. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  917. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  918. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  919. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  920. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  921. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  922. FreeTextDefalut.TextAlign = freeText.Align;
  923. FreeTextDefalut.FontSize = freeText.FontSize;
  924. FreeTextDefalut.FontWeight = freeText.FontWeight;
  925. FreeTextDefalut.FontStyle = freeText.FontStyle;
  926. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  927. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  928. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  929. FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
  930. {
  931. FontColor = freeText.FontColor,
  932. FontFamily = freeText.FontFamily,
  933. Align = freeText.Align,
  934. FontSize = freeText.FontSize,
  935. FontWeight = freeText.FontWeight,
  936. FontStyle = freeText.FontStyle,
  937. BgColor = freeText.BgColor,
  938. Transparency = (annot as FreeTextAnnotArgs).Transparency
  939. };
  940. PDFViewer.SetToolParam(freeTextAnnotArgs);
  941. }
  942. else if (annot is StickyAnnotArgs)
  943. {
  944. var color = (annot as StickyAnnotArgs).Color;
  945. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  946. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  947. StickyDefalut.ForgoundColor = color;
  948. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  949. }
  950. else if (annot is SquareAnnotArgs)
  951. {
  952. var square = annot as SquareAnnotArgs;
  953. var bgColor = square.BgColor;
  954. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  955. var borderColor = square.LineColor;
  956. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  957. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  958. SquareDefalut.BorderColor = borderColor;
  959. SquareDefalut.BackgroundColor = bgColor;
  960. SquareDefalut.Opacity = square.Transparency;
  961. SquareDefalut.Thickness = square.LineWidth;
  962. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  963. if (isSolid)
  964. {
  965. SquareDefalut.DashArray = null;
  966. }
  967. else
  968. {
  969. SquareDefalut.DashArray = new List<double>();
  970. foreach (var item in square.LineDash.Dashes)
  971. {
  972. SquareDefalut.DashArray.Add(item);
  973. }
  974. }
  975. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  976. }
  977. else if (annot is CircleAnnotArgs)
  978. {
  979. var circle = annot as CircleAnnotArgs;
  980. var bgColor = circle.BgColor;
  981. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  982. var borderColor = circle.LineColor;
  983. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  984. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  985. CircleDefalut.BorderColor = borderColor;
  986. CircleDefalut.BackgroundColor = bgColor;
  987. CircleDefalut.Opacity = circle.Transparency;
  988. CircleDefalut.Thickness = circle.LineWidth;
  989. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  990. if (isSolid)
  991. {
  992. CircleDefalut.DashArray = null;
  993. }
  994. else
  995. {
  996. CircleDefalut.DashArray = new List<double>();
  997. foreach (var item in circle.LineDash.Dashes)
  998. {
  999. CircleDefalut.DashArray.Add(item);
  1000. }
  1001. }
  1002. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1003. }
  1004. else if (annot is LineAnnotArgs)
  1005. {
  1006. var line = (annot as LineAnnotArgs);
  1007. var color = (annot as LineAnnotArgs).LineColor;
  1008. Settings.Default.AppProperties.Annotate.LineColor = color;
  1009. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1010. lineDefalut.BorderColor = color;
  1011. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1012. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1013. var isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  1014. if (isSolid)
  1015. {
  1016. lineDefalut.DashArray = null;
  1017. }
  1018. else
  1019. {
  1020. lineDefalut.DashArray = new List<double>();
  1021. foreach (var item in line.LineDash.Dashes)
  1022. {
  1023. lineDefalut.DashArray.Add(item);
  1024. }
  1025. }
  1026. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1027. }
  1028. Settings.Default.Save();
  1029. }
  1030. }
  1031. }
  1032. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1033. {
  1034. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1035. if (Annot == null)
  1036. {
  1037. Annot = new DefaultAnnotProperty();
  1038. Annot.AnnotToolType = annotArgsType;
  1039. }
  1040. return Annot;
  1041. }
  1042. private System.Windows.Controls.Primitives.Popup popup = null;
  1043. //更改颜色
  1044. private async void AnnotColorPalette_Menu(object obj)
  1045. {
  1046. if (obj as CusMenuItem != null)
  1047. {
  1048. var menu = obj as CusMenuItem;
  1049. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1050. if (annot != null)
  1051. {
  1052. var item = new ColorDropBoxPop();
  1053. item.DataContext = menu;
  1054. item.ColorSelected -= AnnotMenu_ColorSelected;
  1055. item.ColorSelected += AnnotMenu_ColorSelected;
  1056. if (popup == null)
  1057. popup = new System.Windows.Controls.Primitives.Popup();
  1058. ContentControl window = null;
  1059. if (PDFViewer.Parent as ContentControl != null)
  1060. window = PDFViewer.Parent as ContentControl;
  1061. else
  1062. window = App.Current.MainWindow;
  1063. popup.Child = item;
  1064. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1065. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1066. popup.PlacementTarget = window;
  1067. popup.IsOpen = true;
  1068. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1069. if (parentWnd != null)
  1070. {
  1071. parentWnd.MouseDown -= parentWnd_MouseDown;
  1072. parentWnd.MouseDown += parentWnd_MouseDown;
  1073. }
  1074. while (popup.IsOpen)
  1075. await Task.Delay(20);
  1076. parentWnd.MouseDown -= parentWnd_MouseDown;
  1077. popup = null;
  1078. }
  1079. }
  1080. }
  1081. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1082. {
  1083. var ui = Mouse.DirectlyOver as FrameworkElement;
  1084. if (ui != null)
  1085. {
  1086. if (popup != null)
  1087. {
  1088. popup.IsOpen = false;
  1089. }
  1090. }
  1091. }
  1092. private void AnnotMenu_ColorSelected(object sender, Color e)
  1093. {
  1094. if (sender != null)
  1095. {
  1096. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1097. if (menu == null) return;
  1098. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1099. if (annot != null)
  1100. {
  1101. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1102. {
  1103. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1104. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1105. AnnotEvent?.UpdateAnnot();
  1106. }
  1107. else if (annot is FreeTextAnnotArgs)
  1108. {
  1109. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1110. if (menu.tag.ToString() == "FontColor")
  1111. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1112. else
  1113. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1114. AnnotEvent?.UpdateAnnot();
  1115. }
  1116. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1117. {
  1118. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1119. if (menu.tag.ToString() == "FillColor")
  1120. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1121. else
  1122. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1123. AnnotEvent?.UpdateAnnot();
  1124. }
  1125. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1126. {
  1127. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1128. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1129. AnnotEvent?.UpdateAnnot();
  1130. }
  1131. }
  1132. }
  1133. }
  1134. //添加笔记
  1135. private void AnnotAddNoteText_Menu(object obj)
  1136. {
  1137. if (obj as CusMenuItem != null)
  1138. {
  1139. var menu = obj as CusMenuItem;
  1140. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1141. PopAnnotNoteText(annot);
  1142. }
  1143. }
  1144. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1145. {
  1146. if (annot != null)
  1147. {
  1148. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1149. args.ClientRect = annot.ClientRect;
  1150. args.AnnotHandlerEventArgs = annot;
  1151. args.PageIndex = annot.PageIndex;
  1152. args.AnnotIndex = annot.AnnotIndex;
  1153. args.EventType = annot.EventType;
  1154. args.CreateTime = annot.CreateTime;
  1155. args.UpdateTime = annot.UpdateTime;
  1156. args.Content = annot.Content;
  1157. args.MarkupContent = annot.MarkupContent;
  1158. args.Author = annot.Author;
  1159. args.Locked = annot.Locked;
  1160. args.ReadOnly = annot.ReadOnly;
  1161. args.FormField = annot.FormField;
  1162. args.Document = PDFViewer.Document;
  1163. DialogParameters value = new DialogParameters();
  1164. value.Add(ParameterNames.Annotation, args);
  1165. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1166. {
  1167. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1168. {
  1169. PDFViewer.UndoManager.CanSave = true;
  1170. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1171. {
  1172. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  1173. //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  1174. events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
  1175. }
  1176. }
  1177. });
  1178. }
  1179. }
  1180. //手绘
  1181. private void FreeHandLineStyle_Menu(object obj)
  1182. {
  1183. if (obj as CusMenuItem != null)
  1184. {
  1185. var menu = obj as CusMenuItem;
  1186. var annot = menu.Parameter as FreehandAnnotArgs;
  1187. if (annot != null)
  1188. {
  1189. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1190. if (menu.tag.ToString() == "Solid")
  1191. {
  1192. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1193. }
  1194. else
  1195. {
  1196. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1197. }
  1198. AnnotEvent?.UpdateAnnot();
  1199. }
  1200. }
  1201. }
  1202. //文本
  1203. private void FreeTextFontFamily_Menu(object obj)
  1204. {
  1205. if (obj as CusMenuItem != null)
  1206. {
  1207. var menu = obj as CusMenuItem;
  1208. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1209. if (annot != null)
  1210. {
  1211. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1212. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1213. AnnotEvent?.UpdateAnnot();
  1214. }
  1215. }
  1216. }
  1217. private void FreeTextAglin_Menu(object obj)
  1218. {
  1219. if (obj as CusMenuItem != null)
  1220. {
  1221. var menu = obj as CusMenuItem;
  1222. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1223. var tag = menu.control.Tag;
  1224. if (annot != null && tag != null)
  1225. {
  1226. var strTag = tag.ToString();
  1227. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1228. if (strTag == "Left")
  1229. {
  1230. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1231. }
  1232. else if (strTag == "Center")
  1233. {
  1234. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1235. }
  1236. else if (strTag == "Right")
  1237. {
  1238. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1239. }
  1240. else if (strTag == "Justify")
  1241. {
  1242. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1243. }
  1244. AnnotEvent?.UpdateAnnot();
  1245. }
  1246. }
  1247. }
  1248. //便签
  1249. private void StrikeNoteEditStrike_Menu(object obj)
  1250. {
  1251. if (obj as CusMenuItem != null)
  1252. {
  1253. var menu = obj as CusMenuItem;
  1254. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1255. if (annot != null)
  1256. {
  1257. var sticky = annot as StickyAnnotArgs;
  1258. sticky.PopupEditWnd();
  1259. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1260. //isRightMenuAddAnnot = false;
  1261. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1262. }
  1263. }
  1264. }
  1265. //形状
  1266. private void ShapeLineStyle_Menu(object obj)
  1267. {
  1268. if (obj as CusMenuItem != null)
  1269. {
  1270. var menu = obj as CusMenuItem;
  1271. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1272. var tag = menu.control.Tag;
  1273. if (annot != null && tag != null)
  1274. {
  1275. var strTag = tag.ToString();
  1276. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1277. if (strTag == "Solid")
  1278. {
  1279. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1280. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1281. }
  1282. else
  1283. {
  1284. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1285. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1286. }
  1287. AnnotEvent?.UpdateAnnot();
  1288. }
  1289. }
  1290. }
  1291. private void ShapeLineDirect_Menu(object obj)
  1292. {
  1293. if (obj as CusMenuItem != null)
  1294. {
  1295. var menu = obj as CusMenuItem;
  1296. var annot = menu.Parameter as LineAnnotArgs;
  1297. var tag = menu.control.Tag;
  1298. if (annot != null && tag != null)
  1299. {
  1300. var strTag = tag.ToString();
  1301. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1302. if (strTag == "Ver")
  1303. {
  1304. annot.SetLineVertical();
  1305. }
  1306. else
  1307. {
  1308. annot.SetLineHorizontal();
  1309. }
  1310. }
  1311. }
  1312. }
  1313. private void Link_Menu(object obj)
  1314. {
  1315. if (obj is CusMenuItem menuItem)
  1316. {
  1317. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1318. {
  1319. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1320. if (result)
  1321. {
  1322. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1323. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1324. if (isTabItemAnnotation)
  1325. {
  1326. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1327. if (viewModel != null)
  1328. {
  1329. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1330. }
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. //图章
  1337. private void StampExportPicture_Menu(object obj)
  1338. {
  1339. if (obj as CusMenuItem != null)
  1340. {
  1341. var menu = obj as CusMenuItem;
  1342. var annot = menu.Parameter as StampAnnotArgs;
  1343. if (annot != null)
  1344. {
  1345. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1346. var format = menu.tag.ToString();
  1347. if (format == "PDF")
  1348. dlg.Filter = "PDF|*.pdf";
  1349. else
  1350. dlg.Filter = format + "|*." + format.ToLower();
  1351. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1352. dlg.FileName = PDFViewer.Document.FileName;
  1353. if (dlg.ShowDialog() == true)
  1354. {
  1355. var stampPicture = dlg.FileName;
  1356. if (menu.tag.ToString() == "PDF")
  1357. {
  1358. var writeStamp = annot.GetStampDrawing();
  1359. var tempDoc = new CPDFViewer();
  1360. tempDoc.CreateDocument();
  1361. if (tempDoc.Document == null)
  1362. {
  1363. AlertsMessage alertsMessage = new AlertsMessage();
  1364. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1365. return;
  1366. }
  1367. byte[] buffer;
  1368. var encoder = new PngBitmapEncoder();
  1369. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1370. using (var memoryStream = new MemoryStream())
  1371. {
  1372. encoder.Save(memoryStream);
  1373. buffer = memoryStream.ToArray();
  1374. }
  1375. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1376. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1377. if (result)
  1378. {
  1379. }
  1380. }
  1381. else
  1382. {
  1383. var writeStamp = annot.GetStampDrawing();
  1384. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1385. {
  1386. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1387. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1388. encoder5.Save(stream5);
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. #endregion 注释右键菜单事件
  1396. #region 快捷键
  1397. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1398. {
  1399. if (KeyEventsHelper.IsSingleKey(Key.Escape))
  1400. {
  1401. //BtnHandIsChecked = true;
  1402. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1403. PDFViewer.ClearSelectAnnots();
  1404. StrAnnotToolChecked = "";
  1405. ShowPropertyPanel(false);
  1406. }
  1407. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  1408. {
  1409. //按住Shift等比缩放
  1410. }
  1411. AnnotToolCtrlAltKey();
  1412. }
  1413. /// <summary>
  1414. /// 按下Ctrl + Alt + 序列键,响应注释工具
  1415. /// </summary>
  1416. private void AnnotToolCtrlAltKey()
  1417. {
  1418. var tuple = GetCtrlAltKey();
  1419. if (tuple != null)
  1420. {
  1421. if (tuple.Item1 == Key.L)
  1422. BtnLinkIsChecked = false;
  1423. if (tuple.Item2 == "Eraser")
  1424. {
  1425. CreateEraseArgs();
  1426. StrAnnotToolChecked = "Freehand";
  1427. return;
  1428. }
  1429. AnnotHandlerEventArgs annotArgs = null;
  1430. StrAnnotToolChecked = tuple.Item2;
  1431. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  1432. if (annotArgs != null)
  1433. {
  1434. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1435. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1436. PDFViewer.SetToolParam(annotArgs);
  1437. PDFViewer.ToolManager.EnableClickCreate = false;
  1438. }
  1439. }
  1440. }
  1441. private Tuple<Key, string> GetCtrlAltKey()
  1442. {
  1443. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  1444. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  1445. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  1446. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  1447. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  1448. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  1449. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  1450. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  1451. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  1452. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  1453. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  1454. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  1455. Key key = Key.None;
  1456. foreach (var item in AnnotToolDir.Keys)
  1457. {
  1458. if (AnnotToolDir[item] == true)
  1459. {
  1460. key = item;
  1461. break;
  1462. }
  1463. }
  1464. if (key == Key.None)
  1465. return null;
  1466. var tag = "";
  1467. if (key == Key.H || key == Key.U || key == Key.S)
  1468. {
  1469. var str = PDFViewer.GetSelectedText();
  1470. if (string.IsNullOrEmpty(str) == false)
  1471. {
  1472. if (key == Key.H)
  1473. tag = "HighLight";
  1474. else if (key == Key.U)
  1475. tag = "UnderLine";
  1476. else if (key == Key.S)
  1477. tag = "Strikeout";
  1478. }
  1479. else
  1480. {
  1481. return null;
  1482. }
  1483. }
  1484. else
  1485. {
  1486. if (AnnotToolDir[Key.P])
  1487. tag = "Freehand";
  1488. else if (AnnotToolDir[Key.T])
  1489. tag = "Freetext";
  1490. else if (AnnotToolDir[Key.N])
  1491. tag = "StickyNote";
  1492. else if (AnnotToolDir[Key.R])
  1493. tag = "Rect";
  1494. else if (AnnotToolDir[Key.O])
  1495. tag = "Circle";
  1496. else if (AnnotToolDir[Key.A])
  1497. tag = "Arrow";
  1498. else if (AnnotToolDir[Key.L])
  1499. tag = "Line";
  1500. else if (AnnotToolDir[Key.E])
  1501. tag = "Eraser";
  1502. }
  1503. if (tag == "")
  1504. return null;
  1505. return new Tuple<Key, string>(key, tag);
  1506. }
  1507. #endregion 快捷键
  1508. #region Navigation
  1509. public bool IsNavigationTarget(NavigationContext navigationContext)
  1510. {
  1511. return true;
  1512. }
  1513. public void OnNavigatedFrom(NavigationContext navigationContext)
  1514. {
  1515. StrAnnotToolChecked = "";
  1516. UnBindingPDFViewerHandler();
  1517. UnBindingEvent();
  1518. }
  1519. public void OnNavigatedTo(NavigationContext navigationContext)
  1520. {
  1521. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1522. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1523. if (viewContentViewModel != null)
  1524. {
  1525. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  1526. }
  1527. BindingPDFViewerHandler();
  1528. BindingEvent();
  1529. LoaedStickyNotePopup();
  1530. //获取当前是否为滚动状态
  1531. // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  1532. BtnHandIsChecked = false;
  1533. HandToolIsCheckedEvent(false);
  1534. }
  1535. #endregion Navigation
  1536. }
  1537. }