AnnotToolContentViewModel.cs 71 KB

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