FillAndSignContentViewModel.cs 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using PDF_Office.ViewModels.Tools;
  15. using ComPDFKitViewer;
  16. using PDF_Office.Helper;
  17. using PDF_Office.Properties;
  18. using PDFSettings;
  19. using System.Windows.Media;
  20. using ComPDFKit.PDFDocument.Action;
  21. using ComPDFKit.PDFDocument;
  22. using System.Diagnostics;
  23. using ComPDFKit.PDFAnnotation;
  24. using PDF_Office.ViewModels.BOTA;
  25. using PDF_Office.Views.BOTA;
  26. using System.Windows.Forms;
  27. using Control = System.Windows.Controls.Control;
  28. using Microsoft.Office.Interop.Word;
  29. using Point = System.Windows.Point;
  30. using System.Windows.Ink;
  31. using PDF_Office.EventAggregators;
  32. using System.Management.Instrumentation;
  33. using Prism.Events;
  34. using System.Windows.Input;
  35. using ContextMenu = System.Windows.Controls.ContextMenu;
  36. using MenuItem = System.Windows.Controls.MenuItem;
  37. using System.Drawing;
  38. using Color = System.Windows.Media.Color;
  39. using Brush = System.Windows.Media.Brush;
  40. using FontFamily = System.Windows.Media.FontFamily;
  41. using ToolTip = System.Windows.Controls.ToolTip;
  42. using ContentControl = System.Windows.Controls.ContentControl;
  43. using MouseEventArgs = System.Windows.Input.MouseEventArgs;
  44. using Pen = System.Windows.Media.Pen;
  45. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  46. using RadioButton = System.Windows.Controls.RadioButton;
  47. using Style = System.Windows.Style;
  48. using PDF_Office.CustomControl;
  49. using System.Windows.Controls.Primitives;
  50. using Window = System.Windows.Window;
  51. using Task = System.Threading.Tasks.Task;
  52. using Size = System.Windows.Size;
  53. using System.Windows.Markup;
  54. namespace PDF_Office.ViewModels.FillAndSign
  55. {
  56. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  57. {
  58. #region
  59. private CPDFViewer PDFViewer;
  60. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  61. private ViewContentViewModel viewContentViewModel;
  62. private bool isRightMenuAddAnnot = false;
  63. private IEventAggregator events;
  64. public List<List<Point>> ShapePoints = new List<List<Point>>();
  65. private string Shape = "HookShape";
  66. private PopMenu FreeHandAnnotPopMenu;
  67. private PopMenu FreeTextAnnotPopMenu;
  68. private PopMenu MultiAnnotPopMenu;
  69. public bool isFirst=true;
  70. private IRegionManager regions { get; set; }
  71. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  72. public static bool IsEdit = false;
  73. public static bool IsSignPoint = false;
  74. public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
  75. public double FillOpacity = 1;
  76. public double LineWidth = 1;
  77. public double LineWidthMultiple = 1;
  78. private bool _HookShapeIsCheck = true;
  79. public bool HookShapeIsCheck
  80. {
  81. get { return _HookShapeIsCheck; }
  82. set { SetProperty(ref _HookShapeIsCheck, value); }
  83. }
  84. #endregion
  85. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  86. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  87. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  88. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  89. #region Command
  90. public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
  91. /// <summary>
  92. /// 按钮名称和属性面板映射字典
  93. /// </summary>
  94. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  95. #endregion
  96. string Unicode = "";
  97. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
  98. {
  99. regions = regionManager;
  100. this.events = events;
  101. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  102. CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
  103. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  104. InitDictionary();
  105. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  106. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  107. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  108. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  109. InitSelectFreeHandAnnotMenu();
  110. InitSelectFreeTextAnnotMenu();
  111. InitSelectMultiAnnotMenu();
  112. SubscribeEvent();
  113. }
  114. #region 事件聚合器(来自AnnotToolContentViewModel)
  115. private void SubscribeEvent()
  116. {
  117. events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
  118. }
  119. private void FromFillAndSign(FillAndSigntEventArgs obj)
  120. {
  121. if(obj != null)
  122. {
  123. if(string.IsNullOrEmpty(obj.Unicode) == false)
  124. {
  125. if(obj.Unicode == "Clear")
  126. {
  127. viewContentViewModel.FillAndSign.Clear();
  128. }
  129. else
  130. {
  131. if(obj.Annots != null && obj.Annots.Count > 0)
  132. {
  133. if (obj.Annots[0].EventType == AnnotArgsType.AnnotFreehand)
  134. {
  135. GetFreehand(obj.Annots);
  136. }
  137. else if(obj.Annots[0].EventType == AnnotArgsType.AnnotFreeText)
  138. {
  139. GetFreetext(obj.Annots);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. #endregion 事件聚合器
  147. private void InitFillAndSignProperty()
  148. {
  149. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
  150. SelectColor = new SolidColorBrush(FreehandDefault.BorderColor != Color.FromArgb(0, 0, 0, 0) ? FreehandDefault.BorderColor : Colors.GreenYellow);
  151. FillOpacity = FreehandDefault.Opacity > 0 ? FreehandDefault.Opacity : 1;
  152. LineWidth = FreehandDefault.Thickness > 0 ? FreehandDefault.Thickness : 1;
  153. }
  154. private System.Windows.Controls.Primitives.Popup popup = null;
  155. private async void AnnotColorPalette_Menu(object obj)
  156. {
  157. if (obj as CusMenuItem != null)
  158. {
  159. var menu = obj as CusMenuItem;
  160. var annot = menu.Parameter as AnnotHandlerEventArgs;
  161. if (annot != null)
  162. {
  163. var item = new ColorDropBoxPop();
  164. item.DataContext = menu;
  165. item.ColorSelected -= AnnotMenu_ColorSelected;
  166. item.ColorSelected += AnnotMenu_ColorSelected;
  167. if (popup == null)
  168. popup = new System.Windows.Controls.Primitives.Popup();
  169. ContentControl window = null;
  170. if (PDFViewer.Parent as ContentControl != null)
  171. window = PDFViewer.Parent as ContentControl;
  172. else
  173. window = App.Current.MainWindow;
  174. popup.Child = item;
  175. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  176. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  177. popup.PlacementTarget = window;
  178. popup.IsOpen = true;
  179. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  180. if (parentWnd != null)
  181. {
  182. parentWnd.MouseDown -= parentWnd_MouseDown;
  183. parentWnd.MouseDown += parentWnd_MouseDown;
  184. }
  185. while (popup.IsOpen)
  186. await Task.Delay(20);
  187. parentWnd.MouseDown -= parentWnd_MouseDown;
  188. popup = null;
  189. }
  190. }
  191. }
  192. private void AnnotMenu_ColorSelected(object sender, Color e)
  193. {
  194. if (sender != null)
  195. {
  196. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  197. if (menu == null) return;
  198. var annot = menu.Parameter as AnnotHandlerEventArgs;
  199. if (annot != null)
  200. {
  201. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  202. {
  203. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  204. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  205. AnnotEvent?.UpdateAnnot();
  206. }
  207. else if (annot is FreeTextAnnotArgs)
  208. {
  209. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  210. if (menu.tag.ToString() == "FontColor")
  211. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  212. else
  213. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  214. AnnotEvent?.UpdateAnnot();
  215. }
  216. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  217. {
  218. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  219. if (menu.tag.ToString() == "FillColor")
  220. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  221. else
  222. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  223. AnnotEvent?.UpdateAnnot();
  224. }
  225. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  226. {
  227. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  228. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  229. AnnotEvent?.UpdateAnnot();
  230. }
  231. }
  232. }
  233. }
  234. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  235. {
  236. var ui = Mouse.DirectlyOver as FrameworkElement;
  237. if (ui != null)
  238. {
  239. if (popup != null)
  240. {
  241. popup.IsOpen = false;
  242. }
  243. }
  244. }
  245. private void FreeTextFontFamily_Menu(object obj)
  246. {
  247. if (obj as CusMenuItem != null)
  248. {
  249. var menu = obj as CusMenuItem;
  250. var annot = menu.Parameter as AnnotHandlerEventArgs;
  251. if (annot != null)
  252. {
  253. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  254. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  255. AnnotEvent?.UpdateAnnot();
  256. }
  257. }
  258. }
  259. private void FreeTextAglin_Menu(object obj)
  260. {
  261. if (obj as CusMenuItem != null)
  262. {
  263. var menu = obj as CusMenuItem;
  264. var annot = menu.Parameter as AnnotHandlerEventArgs;
  265. var tag = menu.control.Tag;
  266. if (annot != null && tag != null)
  267. {
  268. var strTag = tag.ToString();
  269. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  270. if (strTag == "Left")
  271. {
  272. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  273. }
  274. else if (strTag == "Center")
  275. {
  276. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  277. }
  278. else if (strTag == "Right")
  279. {
  280. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  281. }
  282. else if (strTag == "Justify")
  283. {
  284. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  285. }
  286. AnnotEvent?.UpdateAnnot();
  287. }
  288. }
  289. }
  290. private void AnnotDefaultValues_Menu(object obj)
  291. {
  292. if (obj as CusMenuItem != null)
  293. {
  294. var menu = obj as CusMenuItem;
  295. var annot = menu.Parameter as AnnotHandlerEventArgs;
  296. if (annot != null)
  297. {
  298. if (annot is FreehandAnnotArgs)
  299. {
  300. var freeHand = annot as FreehandAnnotArgs;
  301. var color = freeHand.InkColor;
  302. //Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  303. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
  304. FreehandDefault.BorderColor = color;
  305. FreehandDefault.Opacity = freeHand.Transparency;
  306. FreehandDefault.Thickness = freeHand.LineWidth;
  307. FreehandDefault.SaveKey = "FillAndSign";
  308. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  309. if (isSolid)
  310. {
  311. FreehandDefault.DashArray = null;
  312. }
  313. else
  314. {
  315. FreehandDefault.DashArray = new List<double>();
  316. foreach (var item in freeHand.LineDash.Dashes)
  317. {
  318. FreehandDefault.DashArray.Add(item);
  319. }
  320. }
  321. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  322. }
  323. else if (annot is FreeTextAnnotArgs)
  324. {
  325. var freeText = annot as FreeTextAnnotArgs;
  326. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  327. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  328. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  329. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  330. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  331. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  332. FreeTextDefalut.TextAlign = freeText.Align;
  333. FreeTextDefalut.FontSize = freeText.FontSize;
  334. FreeTextDefalut.FontWeight = freeText.FontWeight;
  335. FreeTextDefalut.FontStyle = freeText.FontStyle;
  336. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  337. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  338. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  339. }
  340. }
  341. }
  342. }
  343. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType,string savaKey="")
  344. {
  345. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, savaKey);
  346. if (Annot == null)
  347. {
  348. Annot = new DefaultAnnotProperty();
  349. Annot.AnnotToolType = annotArgsType;
  350. }
  351. return Annot;
  352. }
  353. private void CheckedEvent(RoutedEventArgs e)
  354. {
  355. IsEdit = false;
  356. var control = e.OriginalSource as Control;
  357. //NavigateToProperty(control.Name);
  358. //不创建注释,属于注释模板
  359. bool isTemplateAnnot = false;
  360. bool isSnapshotEdit = false;
  361. AnnotHandlerEventArgs annotArgs = null;
  362. var tag = control.Name;
  363. FindAnnotTypeKey(control.Name, ref annotArgs);
  364. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  365. if (tag == "SnapshotEdit")
  366. {
  367. isSnapshotEdit = true;
  368. }
  369. else if (tag == "Signature" || tag == "Stamp")
  370. {
  371. isTemplateAnnot = true;
  372. }
  373. if (annotArgs != null)
  374. {
  375. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  376. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  377. PDFViewer.SetToolParam(annotArgs);
  378. isRightMenuAddAnnot = false;
  379. }
  380. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  381. if (isTemplateAnnot == false && annotArgs == null)
  382. {
  383. PDFViewer.SetMouseMode(MouseModes.PanTool);
  384. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  385. }
  386. else
  387. {
  388. if (isSnapshotEdit == true)
  389. {
  390. ShowPropertyPanel(false);
  391. isSnapshotEdit = false;
  392. }
  393. else
  394. {
  395. ShowPropertyPanel(true);
  396. }
  397. }
  398. }
  399. private void InitCheckedEvent(string e)
  400. {
  401. IsEdit = false;
  402. //NavigateToProperty(control.Name);
  403. //不创建注释,属于注释模板
  404. bool isTemplateAnnot = false;
  405. bool isSnapshotEdit = false;
  406. AnnotHandlerEventArgs annotArgs = null;
  407. var tag = e;
  408. FindAnnotTypeKey(e, ref annotArgs);
  409. if (e == "RbtnSign") { isTemplateAnnot = true; }
  410. if (tag == "SnapshotEdit")
  411. {
  412. isSnapshotEdit = true;
  413. }
  414. else if (tag == "Signature" || tag == "Stamp")
  415. {
  416. isTemplateAnnot = true;
  417. }
  418. if (annotArgs != null)
  419. {
  420. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  421. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  422. PDFViewer.SetToolParam(annotArgs);
  423. isRightMenuAddAnnot = false;
  424. }
  425. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  426. if (isTemplateAnnot == false && annotArgs == null)
  427. {
  428. PDFViewer.SetMouseMode(MouseModes.PanTool);
  429. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  430. }
  431. else
  432. {
  433. if (isSnapshotEdit == true)
  434. {
  435. ShowPropertyPanel(false);
  436. isSnapshotEdit = false;
  437. }
  438. else
  439. {
  440. ShowPropertyPanel(true);
  441. }
  442. }
  443. }
  444. //注释工具
  445. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  446. {
  447. LineWidthMultiple = 1;
  448. IsSignPoint = false;
  449. switch (tag)
  450. {
  451. case "RbtnDate":
  452. case "RbtnText"://文本
  453. annotArgs = GetFreetext();
  454. break;
  455. case "Freetext"://文本
  456. annotArgs = GetFreetext();
  457. break;
  458. case "RbtnSign"://签名
  459. annotArgs = GetSignature();
  460. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  461. break;
  462. case "RbtnTick"://勾
  463. Shape = "HookShape";
  464. ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  465. annotArgs = GetStamp();
  466. break;
  467. case "RbtnFork"://叉
  468. Shape = "ForkShape";
  469. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
  470. annotArgs = GetStamp();
  471. break;
  472. case "RbtnRectangle"://矩形
  473. Shape = "RectShape";
  474. ShapePoints = new List<List<Point>> { new List<Point> { new Point(5, 5), new Point(28, 5) }, new List<Point> { new Point(28, 5), new Point(28, 27) }, new List<Point> { new Point(28, 27), new Point(5, 27) }, new List<Point> { new Point(5, 27), new Point(5, 5) } };
  475. annotArgs = GetStamp();
  476. break;
  477. case "RbtnLine"://下划线
  478. Shape = "LineShape";
  479. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  480. annotArgs = GetStamp();
  481. break;
  482. case "RbtnPoint":
  483. IsSignPoint = true;
  484. Shape = "DotShape";
  485. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  486. LineWidthMultiple = 5;
  487. annotArgs = GetStamp();
  488. break;
  489. default://图章
  490. break;
  491. }
  492. }
  493. /// <summary>
  494. /// 签名
  495. /// </summary>
  496. /// <returns></returns>
  497. private AnnotHandlerEventArgs GetSignature()
  498. {
  499. AddToPropertyPanel("SignatureAnnotProperty");
  500. return null;
  501. }
  502. /// <summary>
  503. /// 图章
  504. /// </summary>
  505. /// <returns></returns>
  506. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  507. {
  508. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  509. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  510. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  511. //PDFViewer.SetToolParam(stampArgs);
  512. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  513. //stampAnnotArgs.Opacity = 1;
  514. //stampAnnotArgs.StampText = "APPROVED";
  515. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  516. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  517. stampAnnotArgs.IsContinueMode = true;
  518. stampAnnotArgs.IsSignPoint = IsSignPoint;
  519. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  520. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  521. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  522. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  523. if (stampAnnotArgs != null)
  524. stampAnnotArgsList.Add(stampAnnotArgs);
  525. //if (selectedArgs != null) {
  526. //var annot = selectedArgs[0];
  527. //if (annot != null)
  528. //{
  529. // foreach (var item in selectedArgs)
  530. // {
  531. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  532. // }
  533. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  534. // return stampAnnotArgs;
  535. //}
  536. // }
  537. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  538. return stampAnnotArgs;
  539. }
  540. public void SetStamp()
  541. {
  542. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  543. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  544. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  545. //PDFViewer.SetToolParam(stampArgs);
  546. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  547. //stampAnnotArgs.Opacity = 1;
  548. //stampAnnotArgs.StampText = "APPROVED";
  549. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  550. stampAnnotArgs.IsContinueMode = true;
  551. stampAnnotArgs.IsSignPoint = IsSignPoint;
  552. stampAnnotArgs.Opacity = FillOpacity;
  553. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  554. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  555. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  556. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  557. if (stampAnnotArgs != null)
  558. stampAnnotArgsList.Add(stampAnnotArgs);
  559. //AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  560. bool isTemplateAnnot = false;
  561. bool isSnapshotEdit = false;
  562. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  563. if (annotArgs != null)
  564. {
  565. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  566. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  567. PDFViewer.SetToolParam(annotArgs);
  568. isRightMenuAddAnnot = false;
  569. }
  570. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  571. if (isTemplateAnnot == false && annotArgs == null)
  572. {
  573. PDFViewer.SetMouseMode(MouseModes.PanTool);
  574. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  575. }
  576. else
  577. {
  578. if (isSnapshotEdit == true)
  579. {
  580. ShowPropertyPanel(false);
  581. isSnapshotEdit = false;
  582. }
  583. else
  584. {
  585. ShowPropertyPanel(true);
  586. }
  587. }
  588. }
  589. /// <summary>
  590. /// 手绘
  591. /// </summary>
  592. /// <param name="selectedArgs"></param>
  593. /// <returns></returns>
  594. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  595. {
  596. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  597. List<AnnotHandlerEventArgs> newSelectedArgs = new List<AnnotHandlerEventArgs>();
  598. FreehandAnnotArgs freehandArgs = null;
  599. if (selectedArgs == null || selectedArgs.Count == 0)
  600. {
  601. freehandArgs = new FreehandAnnotArgs();
  602. var annotate = Settings.Default.AppProperties.Annotate;
  603. if (annotate != null)
  604. {
  605. freehandArgs.InkColor = annotate.FreeHandColor;
  606. }
  607. else
  608. {
  609. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  610. }
  611. freehandArgs.RawPointList = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  612. freehandArgs.Transparency = 1;
  613. freehandArgs.LineWidth = 2;
  614. if (freehandArgs != null)
  615. {
  616. selectedArgs = new List<AnnotHandlerEventArgs>();
  617. selectedArgs.Add(freehandArgs);
  618. }
  619. }
  620. else
  621. {
  622. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  623. foreach (var item in selectedArgs)
  624. {
  625. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  626. foreach (var point in viewContentViewModel.FillAndSign)
  627. {
  628. if ((item as FreehandAnnotArgs).PageIndex == point.Item1 && (item as FreehandAnnotArgs).AnnotIndex == point.Item2)
  629. {
  630. newSelectedArgs.Add(item);
  631. }
  632. }
  633. }
  634. freehandArgs.RawPointList = ShapePoints;
  635. freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  636. freehandArgs.Transparency = 1;
  637. freehandArgs.LineWidth = LineWidth;
  638. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  639. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  640. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  641. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  642. annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  643. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  644. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  645. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  646. //GetStamp();
  647. return freehandArgs;
  648. }
  649. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  650. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  651. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  652. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  653. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  654. return freehandArgs;
  655. }
  656. private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
  657. {
  658. if (leftpoints.Count == rightpoints.Count)
  659. {
  660. if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
  661. }
  662. return false;
  663. }
  664. /// <summary>
  665. /// 文本
  666. /// </summary>
  667. /// <param name="selectedfreetextArgs"></param>
  668. /// <returns></returns>
  669. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  670. {
  671. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  672. FreeTextAnnotArgs freetextArgs = null;
  673. TextAlignment textAlignment;
  674. if (selectedArgs == null || selectedArgs.Count == 0)
  675. {
  676. freetextArgs = new FreeTextAnnotArgs();
  677. freetextArgs.Align = TextAlignment.Left;
  678. freetextArgs.BgColor = Colors.Transparent;
  679. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  680. freetextArgs.FontColor = Colors.Black;
  681. freetextArgs.FontSize = 14;
  682. freetextArgs.Transparency = 1;
  683. freetextArgs.LineColor = Colors.Black;
  684. freetextArgs.LineWidth = 0;
  685. freetextArgs.TextContent = string.Empty;
  686. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  687. if (annotProperty != null)
  688. {
  689. freetextArgs.Align = annotProperty.TextAlign;
  690. freetextArgs.BgColor = annotProperty.BackgroundColor;
  691. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  692. freetextArgs.FontColor = annotProperty.ForgoundColor;
  693. freetextArgs.FontSize = annotProperty.FontSize;
  694. freetextArgs.Transparency = annotProperty.Opacity;
  695. freetextArgs.LineColor = annotProperty.BorderColor;
  696. freetextArgs.LineWidth = annotProperty.Thickness;
  697. freetextArgs.TextContent = annotProperty.NoteText;
  698. freetextArgs.FontWeight = annotProperty.FontWeight;
  699. freetextArgs.FontStyle = annotProperty.FontStyle;
  700. }
  701. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  702. if (align == 0)
  703. textAlignment = TextAlignment.Left;
  704. else if (align == 1)
  705. textAlignment = TextAlignment.Center;
  706. else
  707. textAlignment = TextAlignment.Right;
  708. if (freetextArgs != null)
  709. {
  710. selectedArgs = new List<AnnotHandlerEventArgs>();
  711. selectedArgs.Add(freetextArgs);
  712. }
  713. }
  714. else
  715. {
  716. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  717. textAlignment = freetextArgs.Align;
  718. }
  719. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  720. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  721. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  722. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  723. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  724. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  725. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  726. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  727. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  728. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  729. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  730. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  731. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  732. return freetextArgs;
  733. }
  734. /// <summary>
  735. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  736. /// </summary>
  737. /// <param name="viewContent">对应的注释面板</param>
  738. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  739. /// <param name="annot">注释</param>
  740. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  741. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  742. {
  743. if (annots != null && annots.Count != 0)
  744. {
  745. propertyPanel.annotlists = annots;
  746. propertyPanel.annot = annots[0];
  747. }
  748. else
  749. {
  750. propertyPanel.annotlists = null;
  751. propertyPanel.annot = null;
  752. }
  753. if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
  754. {
  755. if (annots.Count > 1)
  756. {
  757. if (propertyPanel.AnnotEvents == null)
  758. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  759. propertyPanel.AnnotEvents.Clear();
  760. foreach (var itemAnnot in annots)
  761. {
  762. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  763. //PDFViewer.SelectAnnotation(itemAnnot.PageIndex, itemAnnot.AnnotIndex);
  764. propertyPanel.AnnotEvents.Add(eventitem);
  765. }
  766. }
  767. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  768. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  769. {
  770. propertyPanel.AnnotEvent = annotAttribEvent;
  771. }
  772. }
  773. if (toolTag == "Freetext")
  774. {
  775. propertyPanel.SetIsTextFill(true);
  776. }
  777. else
  778. {
  779. propertyPanel.SetIsTextFill(false);
  780. }
  781. if (string.IsNullOrEmpty(viewContent) == false)
  782. {
  783. if (isUpData) { return; }
  784. if (viewContent == "ShapFillProperty") {
  785. NavigateToProperty(viewContent, propertyPanel); return; }
  786. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  787. }
  788. }
  789. private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
  790. {
  791. NavigationParameters values = new NavigationParameters();
  792. values.Add(ParameterNames.PDFViewer, PDFViewer);
  793. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  794. values.Add("Shape", Shape);
  795. values.Add("FillAndSignContentViewModel", this);
  796. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  797. viewContentViewModel.IsPropertyOpen = true;
  798. }
  799. /// <summary>
  800. /// 初始化按钮名称-属性面板字典
  801. /// </summary>
  802. private void InitDictionary()
  803. {
  804. btnToProperty["RbtnText"] = "TextFillProperty";
  805. btnToProperty["RbtnTick"] = "ShapFillProperty";
  806. btnToProperty["RbtnFork"] = "ShapFillProperty";
  807. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  808. btnToProperty["RbtnLine"] = "ShapFillProperty";
  809. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  810. btnToProperty["RbtnDate"] = "DateFillProperty";
  811. btnToProperty["RbtnSign"] = "";
  812. }
  813. /// <summary>
  814. /// 手绘
  815. /// </summary>
  816. private void InitSelectFreeHandAnnotMenu()
  817. {
  818. var popMenu = new ContextMenu();
  819. PopMenu pop = new PopMenu(popMenu);
  820. var menuItem = new MenuItem();
  821. menuItem.Name = "FreeHandCopy";
  822. menuItem.Header = "复制";
  823. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  824. menuItem = new MenuItem();
  825. menuItem.Name = "FreeHandCut";
  826. menuItem.Header = "剪切";
  827. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  828. menuItem = new MenuItem();
  829. menuItem.Name = "FreeHandPaste";
  830. menuItem.Header = "粘贴";
  831. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  832. menuItem = new MenuItem();
  833. menuItem.Name = "FreeHandDelete";
  834. menuItem.Header = "删除";
  835. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  836. pop.AddItem(GetSeparator());
  837. menuItem = new MenuItem();
  838. menuItem.Name = "FreeHandDefault";
  839. menuItem.Header = "设置当前属性为默认值";
  840. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  841. FreeHandAnnotPopMenu = pop;
  842. }
  843. /// <summary>
  844. /// 文本
  845. /// </summary>
  846. private void InitSelectFreeTextAnnotMenu()
  847. {
  848. var popMenu = new ContextMenu();
  849. PopMenu pop = new PopMenu(popMenu);
  850. var menuItem = new MenuItem();
  851. menuItem.Name = "FreeTextCopy";
  852. menuItem.Header = "复制";
  853. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  854. menuItem = new MenuItem();
  855. menuItem.Name = "FreeTextCut";
  856. menuItem.Header = "剪切";
  857. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  858. menuItem = new MenuItem();
  859. menuItem.Name = "FreeTextPaste";
  860. menuItem.Header = "粘贴";
  861. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  862. menuItem = new MenuItem();
  863. menuItem.Name = "FreeTextDelete";
  864. menuItem.Header = "删除";
  865. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  866. pop.AddItem(GetSeparator());
  867. menuItem = new MenuItem();
  868. menuItem.Name = "FreeTextColor";
  869. menuItem.Header = "字体颜色";
  870. menuItem.Tag = "FontColor";
  871. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  872. menuItem = new MenuItem();
  873. menuItem.Name = "FreeTextColor";
  874. menuItem.Header = "填充颜色";
  875. menuItem.Tag = "FillColor";
  876. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  877. menuItem = new MenuItem();
  878. menuItem.Name = "FreeTextFontFamily";
  879. menuItem.Header = "字体";
  880. pop.AddItem(menuItem);
  881. var family = TextFont.GetFamily();
  882. foreach (var item in family)
  883. {
  884. RadioButton familyRdioBtn = new RadioButton();
  885. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  886. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  887. familyRdioBtn.Name = item.ValueStr;
  888. familyRdioBtn.Tag = item.ValueStr;
  889. familyRdioBtn.GroupName = "FontFamily";
  890. familyRdioBtn.Content = item.Content;
  891. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  892. }
  893. menuItem = new MenuItem();
  894. menuItem.Name = "FreeTextAglin";
  895. menuItem.Header = "文本对齐";
  896. pop.AddItem(menuItem);
  897. var radioButton = new RadioButton();
  898. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  899. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  900. radioButton.Name = "FreeTextAglinLeft";
  901. radioButton.Tag = "Left";
  902. radioButton.GroupName = "Aglin";
  903. radioButton.Content = "左对齐";
  904. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  905. radioButton = new RadioButton();
  906. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  907. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  908. radioButton.Name = "FreeTextAglinCenter";
  909. radioButton.Tag = "Center";
  910. radioButton.GroupName = "Aglin";
  911. radioButton.Content = "居中对齐";
  912. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  913. radioButton = new RadioButton();
  914. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  915. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  916. radioButton.Name = "FreeTextAglinRight";
  917. radioButton.Tag = "Right";
  918. radioButton.GroupName = "Aglin";
  919. radioButton.Content = "右对齐";
  920. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  921. radioButton = new RadioButton();
  922. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  923. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  924. radioButton.Name = "FreeTextAglinJustify";
  925. radioButton.Tag = "Justify";
  926. radioButton.GroupName = "Aglin";
  927. radioButton.Content = "两端对齐";
  928. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  929. menuItem = new MenuItem();
  930. menuItem.Name = "FreeHandDefault";
  931. menuItem.Header = "设置当前属性为默认值";
  932. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  933. FreeTextAnnotPopMenu = pop;
  934. }
  935. /// <summary>
  936. /// 多选注释
  937. /// </summary>
  938. private void InitSelectMultiAnnotMenu()
  939. {
  940. var popMenu = new ContextMenu();
  941. PopMenu pop = new PopMenu(popMenu);
  942. var menuItem = new MenuItem();
  943. menuItem.Name = "MultiCopy";
  944. menuItem.Header = "复制";
  945. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  946. menuItem = new MenuItem();
  947. menuItem.Name = "MultiCut";
  948. menuItem.Header = "剪切";
  949. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  950. menuItem = new MenuItem();
  951. menuItem.Name = "MultiDelete";
  952. menuItem.Header = "删除";
  953. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  954. MultiAnnotPopMenu = pop;
  955. }
  956. private Separator GetSeparator()
  957. {
  958. Separator separator = new Separator();
  959. separator.Height = 1;
  960. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  961. separator.BorderThickness = new Thickness(1);
  962. return separator;
  963. }
  964. private void BindingPDFViewerHandler()
  965. {
  966. //来自PDFViewer的响应事件
  967. if (PDFViewer != null)
  968. {
  969. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  970. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  971. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  972. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  973. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  974. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  975. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  976. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  977. }
  978. }
  979. private void UnBindingPDFViewerHandler()
  980. {
  981. if (PDFViewer != null)
  982. {
  983. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  984. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  985. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  986. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  987. }
  988. }
  989. //在注释工具的状态下,右键菜单
  990. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  991. {
  992. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  993. return;
  994. switch (e.CommandType)
  995. {
  996. case CommandType.Context:
  997. if (e.AnnotEventArgsList.Count > 0)
  998. {
  999. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  1000. {
  1001. //绑定标记密文处右键菜单
  1002. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  1003. }
  1004. else
  1005. {
  1006. if (e.AnnotEventArgsList.Count == 1)
  1007. {
  1008. var selectedAnnot = e.AnnotEventArgsList[0];
  1009. switch (selectedAnnot.EventType)
  1010. {
  1011. case AnnotArgsType.AnnotFreehand:
  1012. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1013. break;
  1014. case AnnotArgsType.AnnotFreeText:
  1015. e.PopupMenu= FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1016. break;
  1017. }
  1018. }
  1019. else
  1020. {
  1021. bool isHigh = true;//是否为高亮
  1022. foreach (var item in e.AnnotEventArgsList)
  1023. {
  1024. if (isHightAnnot(item) == false)
  1025. {
  1026. isHigh = false;
  1027. break;
  1028. }
  1029. }
  1030. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  1031. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  1032. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  1033. }
  1034. }
  1035. if (e.PopupMenu != null)
  1036. {
  1037. e.Handle = true;
  1038. }
  1039. }
  1040. else
  1041. {
  1042. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  1043. {
  1044. if (e.PopupMenu != null)
  1045. {
  1046. e.Handle = true;
  1047. }
  1048. }
  1049. else
  1050. {
  1051. e.PopupMenu = ViewerContextMenu(sender);
  1052. if (e.PopupMenu != null)
  1053. {
  1054. e.Handle = true;
  1055. }
  1056. }
  1057. }
  1058. break;
  1059. }
  1060. }
  1061. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1062. {
  1063. if (e != null && e.DrawContext != null)
  1064. {
  1065. Rect hoverRect = new Rect(
  1066. e.PaintRect.Left - 2,
  1067. e.PaintRect.Top - 2,
  1068. e.PaintRect.Width + 4,
  1069. e.PaintRect.Height + 4);
  1070. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1071. hoverPen.DashStyle = DashStyles.Dash;
  1072. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1073. //Todo:目前ComPDFKit.Viewer没有e.Annot参数
  1074. //便签,显示ToolTip内容
  1075. //if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1076. //{
  1077. // if (PDFViewer.ToolTip == null)
  1078. // {
  1079. // var content = e.Annot.GetContent();
  1080. // if (string.IsNullOrEmpty(content) == false)
  1081. // {
  1082. // ToolTip TipChild = new ToolTip();
  1083. // TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1084. // TipChild.MaxWidth = 246;
  1085. // TipChild.Content = content;
  1086. // TipChild.Visibility = Visibility.Visible;
  1087. // TipChild.IsOpen = true;
  1088. // TipChild.Placement = PlacementMode.Right;
  1089. // var rec = e.Annot.GetRect();
  1090. // TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
  1091. // TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1092. // TipChild.Placement = PlacementMode.MousePoint;
  1093. // PDFViewer.ToolTip = TipChild;
  1094. // oldRect = hoverRect;
  1095. // PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1096. // PDFViewer.MouseMove += PDFViewer_MouseMove;
  1097. // return;
  1098. // }
  1099. // }
  1100. //}
  1101. }
  1102. CloseAnnotToolTip();
  1103. }
  1104. private Rect oldRect = new Rect(0, 0, 0, 0);
  1105. private void CloseAnnotToolTip()
  1106. {
  1107. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1108. {
  1109. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1110. oldTips.IsOpen = false;
  1111. oldTips.Visibility = Visibility.Collapsed;
  1112. PDFViewer.ToolTip = null;
  1113. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1114. oldRect = new Rect(0, 0, 0, 0);
  1115. }
  1116. }
  1117. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1118. {
  1119. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1120. {
  1121. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1122. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1123. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1124. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1125. {
  1126. CloseAnnotToolTip();
  1127. }
  1128. }
  1129. }
  1130. private ContextMenu ViewerContextMenu(object sender)
  1131. {
  1132. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1133. ViewerContextMenu_Loaded(contextMenu, sender);
  1134. return contextMenu;
  1135. }
  1136. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1137. {
  1138. ContextMenu contextMenu = sender as ContextMenu;
  1139. if (contextMenu.Items.Count > 0)
  1140. {
  1141. int index = PDFViewer.CurrentIndex;
  1142. //检测是否已存在相同数据
  1143. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1144. foreach (var item in contextMenu.Items)
  1145. {
  1146. if (item is Separator separator)
  1147. {
  1148. separator.Visibility = visibility;
  1149. }
  1150. if (item is MenuItem menuItem1)
  1151. {
  1152. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1153. //{
  1154. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1155. //}
  1156. switch (menuItem1.Tag.ToString())
  1157. {
  1158. case "Paste":
  1159. //粘贴
  1160. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1161. //{
  1162. // menuItem1.IsEnabled = false;
  1163. // menuItem1.Opacity = 0.5;
  1164. //}
  1165. //else
  1166. //{
  1167. // menuItem1.IsEnabled = true;
  1168. // menuItem1.Opacity = 1;
  1169. //}
  1170. menuItem1.CommandTarget = (UIElement)e;
  1171. menuItem1.Command = ApplicationCommands.Paste;
  1172. break;
  1173. case "AddAnnotation":
  1174. menuItem1.Visibility = visibility;
  1175. break;
  1176. case "HiddenAnnot":
  1177. menuItem1.Visibility = visibility;
  1178. break;
  1179. case "DisplayAnnot":
  1180. menuItem1.Visibility = visibility;
  1181. break;
  1182. case "AddBookMark":
  1183. menuItem1.Visibility = visibility;
  1184. break;
  1185. case "DelBookMark":
  1186. menuItem1.Visibility = visibility;
  1187. break;
  1188. case "ToolMode":
  1189. menuItem1.Visibility = visibility;
  1190. break;
  1191. case "ReadModel":
  1192. menuItem1.Visibility = visibility;
  1193. break;
  1194. case "UnReadModel":
  1195. menuItem1.Visibility = visibility;
  1196. break;
  1197. case "ViewZoom":
  1198. menuItem1.Visibility = visibility;
  1199. break;
  1200. case "PageDisplay":
  1201. menuItem1.Visibility = visibility;
  1202. break;
  1203. case "Select":
  1204. menuItem1.Click -= Select_Click;
  1205. menuItem1.Click += Select_Click;
  1206. break;
  1207. case "Print":
  1208. menuItem1.Command = viewContentViewModel.PrintCommand;
  1209. break;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. private void Select_Click(object sender, RoutedEventArgs e)
  1216. {
  1217. if (viewContentViewModel.OpenBOTA == false)
  1218. {
  1219. viewContentViewModel.OpenBOTA = true;
  1220. }
  1221. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1222. if (isBook == false)
  1223. {
  1224. bOTAContent.TabItemSearch.IsSelected = true;
  1225. }
  1226. }
  1227. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1228. {
  1229. bool isTabItem = false;
  1230. bOTAContentViewModel = null;
  1231. bOTAContent = null;
  1232. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1233. {
  1234. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1235. var model = views.FirstOrDefault(q => q is BOTAContent);
  1236. if (model is BOTAContent bOTAContent1)
  1237. {
  1238. bOTAContent = bOTAContent1;
  1239. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1240. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1241. {
  1242. isTabItem = true;
  1243. }
  1244. }
  1245. //foreach (var item in views)
  1246. //{
  1247. // if (item is BOTAContent bOTAContent1)
  1248. // {
  1249. // bOTAContent = bOTAContent1;
  1250. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1251. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1252. // {
  1253. // isTabItem = true;
  1254. // break;
  1255. // }
  1256. // }
  1257. //}
  1258. }
  1259. return isTabItem;
  1260. }
  1261. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1262. {
  1263. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1264. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1265. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1266. annot.EventType == AnnotArgsType.AnnotStrikeout
  1267. )
  1268. {
  1269. return true;
  1270. }
  1271. else
  1272. {
  1273. return false;
  1274. }
  1275. }
  1276. //注释编辑事件
  1277. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1278. {
  1279. if (e != null && e.Count > 0)
  1280. {
  1281. for (int i = 0; i < e.Count; i++)
  1282. {
  1283. AnnotEditEvent editEvent = e[i];
  1284. switch (editEvent.EditAction)
  1285. {
  1286. case ActionType.Add:
  1287. int pageindex = editEvent.PageIndex;
  1288. int annotindex = editEvent.AnnotIndex;
  1289. viewContentViewModel.FillAndSign.Add(new Tuple<int,int>(pageindex, annotindex));
  1290. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1291. break;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. //选中和非选中注释,右键菜单
  1297. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1298. {
  1299. if (e != null)
  1300. {
  1301. var annot = e.AnnotItemsList[0];
  1302. if (annot != null)
  1303. {
  1304. if (e.AnnotItemsList.Count == 1)
  1305. {
  1306. //IsEdit = false;
  1307. //IsAnnotCreateReset:是否为创建注释的状态
  1308. if (e.IsAnnotCreateReset == false)
  1309. {
  1310. GetSelectedAnnots(e);
  1311. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1312. //PDFViewer.SetToolParam(annot);
  1313. }
  1314. else
  1315. {
  1316. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1317. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1318. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1319. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1320. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1321. annot.EventType != AnnotArgsType.AnnotLink &&
  1322. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1323. annot.EventType != AnnotArgsType.AnnotSticky
  1324. )
  1325. {
  1326. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1327. {
  1328. foreach (var item in ToolExpandDict)
  1329. {
  1330. if (item.Value == e.AnnotItemsList[0].EventType)
  1331. {
  1332. annot = null;//新建注释时,回到默认值
  1333. FindAnnotTypeKey(item.Key, ref annot);
  1334. break;
  1335. }
  1336. }
  1337. }
  1338. }
  1339. //else
  1340. //PDFViewer.SetToolParam(annot);
  1341. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1342. if (isRightMenuAddAnnot)
  1343. {
  1344. ShowPropertyPanel(false);
  1345. }
  1346. else
  1347. {
  1348. ShowPropertyPanel();
  1349. }
  1350. }
  1351. }
  1352. else
  1353. {
  1354. bool isDifferentAnnotTyle = false;
  1355. var lastAnnot = annot;
  1356. foreach (var item in e.AnnotItemsList)
  1357. {
  1358. if (lastAnnot.EventType != item.EventType)
  1359. {
  1360. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1361. {
  1362. lastAnnot = item;
  1363. continue;
  1364. }
  1365. lastAnnot = item;
  1366. isDifferentAnnotTyle = true;
  1367. break;
  1368. }
  1369. }
  1370. if (isDifferentAnnotTyle)
  1371. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1372. else
  1373. GetSelectedAnnots(e);
  1374. }
  1375. }
  1376. }
  1377. else
  1378. {
  1379. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1380. }
  1381. }
  1382. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1383. //{
  1384. // if (e != null && e.Count > 0)
  1385. // {
  1386. // for (int i = 0; i < e.Count; i++)
  1387. // {
  1388. // AnnotEditEvent editEvent = e[i];
  1389. // switch (editEvent.EditAction)
  1390. // {
  1391. // case ActionType.Add:
  1392. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1393. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  1394. // {
  1395. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1396. // if (viewModel != null)
  1397. // {
  1398. // int pageindex = editEvent.PageIndex;
  1399. // int annotindex = editEvent.AnnotIndex;
  1400. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1401. // }
  1402. // }
  1403. // break;
  1404. // case ActionType.Del:
  1405. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1406. // if (isTabItemAnnotation)
  1407. // {
  1408. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1409. // if (viewModel != null)
  1410. // {
  1411. // int pageindex = editEvent.PageIndex;
  1412. // int annotindex = editEvent.AnnotIndex;
  1413. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  1414. // }
  1415. // }
  1416. // break;
  1417. // case ActionType.Modify:
  1418. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1419. // if (bOTAContent.TabItemAnnotation.IsSelected)
  1420. // {
  1421. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1422. // if (viewModel != null)
  1423. // {
  1424. // int pageindex = editEvent.PageIndex;
  1425. // int annotindex = editEvent.AnnotIndex;
  1426. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  1427. // }
  1428. // }
  1429. // break;
  1430. // case ActionType.TextEdit:
  1431. // break;
  1432. // default:
  1433. // break;
  1434. // }
  1435. // }
  1436. // }
  1437. //}
  1438. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1439. {
  1440. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1441. annot.EventType == AnnotArgsType.AnnotSquare ||
  1442. annot.EventType == AnnotArgsType.AnnotLine
  1443. )
  1444. {
  1445. return true;
  1446. }
  1447. else
  1448. {
  1449. return false;
  1450. }
  1451. }
  1452. private void GetSelectedAnnots(AnnotAttribEvent e)
  1453. {
  1454. IsEdit = true;
  1455. var annot = e.AnnotItemsList[0];
  1456. switch (annot.EventType)
  1457. {
  1458. case AnnotArgsType.AnnotFreeText:
  1459. GetFreetext(e.AnnotItemsList);
  1460. break;
  1461. case AnnotArgsType.AnnotFreehand:
  1462. GetFreehand(e.AnnotItemsList);
  1463. break;
  1464. }
  1465. }
  1466. private void ShowPropertyPanel(bool show = true)
  1467. {
  1468. viewContentViewModel.IsPropertyOpen = show;
  1469. }
  1470. #region Navigation
  1471. public bool IsNavigationTarget(NavigationContext navigationContext)
  1472. {
  1473. return true;
  1474. }
  1475. public void OnNavigatedFrom(NavigationContext navigationContext)
  1476. {
  1477. UnBindingPDFViewerHandler();
  1478. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1479. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1480. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1481. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1482. ShowPropertyPanel(false);
  1483. }
  1484. public void OnNavigatedTo(NavigationContext navigationContext)
  1485. {
  1486. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1487. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1488. BindingPDFViewerHandler();
  1489. HookShapeIsCheck = true;
  1490. InitFillAndSignProperty();
  1491. InitCheckedEvent("RbtnTick");
  1492. IsEdit = false;
  1493. }
  1494. #endregion
  1495. }
  1496. }