ViewContentViewModel.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using ComPDFKitViewer.PdfViewer;
  10. using Prism.Regions;
  11. using DryIoc;
  12. using System.Diagnostics;
  13. using Prism.Services.Dialogs;
  14. using PDF_Office.CustomControl;
  15. using PDF_Office.Model;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.IO;
  19. using PDFSettings;
  20. using ComPDFKitViewer.AnnotEvent;
  21. using PDF_Office.ViewModels.Tools;
  22. using PDF_Office.Views;
  23. using Prism.Events;
  24. using PDF_Office.EventAggregators;
  25. using PDF_Office.Views.EditTools.Background;
  26. using PDF_Office.Views.Dialog;
  27. using PDF_Office.Helper;
  28. using System.Security.Policy;
  29. using System.Windows.Documents;
  30. using ComPDFKit.PDFDocument;
  31. using PDFSettings.Settings;
  32. namespace PDF_Office.ViewModels
  33. {
  34. public class ViewContentViewModel : BindableBase, INavigationAware
  35. {
  36. #region 属性、变量
  37. public CPDFViewer PDFViewer { get; set; }
  38. public MainContentViewModel mainViewModel { get; set; }
  39. public IRegionManager region;
  40. public IDialogService dialogs;
  41. public IEventAggregator events;
  42. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  43. public string ViwerRegionName { get; set; }
  44. /// <summary>
  45. /// 分屏视图的region名称
  46. /// </summary>
  47. public string SplitViewerRegionName { get; set; }
  48. /// <summary>
  49. /// OCR视图名称
  50. /// </summary>
  51. public string OCRViewerRegionName { get; set; }
  52. public string BOTARegionName { get; set; }
  53. public string PropertyRegionName { get; set; }
  54. public string ToolContentRegionName { get; set; }
  55. public string ToolsBarContentRegionName { get; set; }
  56. /// <summary>
  57. /// 顶部提示的Content
  58. /// </summary>
  59. public string TipContentRegionName { get; set; }
  60. public string ReadModeRegionName { get; set; }
  61. public string ConverterBarContentRegionName { get; set; }
  62. public string TextEditContentRegionName { get; set; }
  63. public string BackgroundContentRegionName { get; set; }
  64. /// <summary>
  65. /// 文档的密码
  66. /// </summary>
  67. public string PassWord { get; set; }
  68. private Visibility tipVisible = Visibility.Collapsed;
  69. /// <summary>
  70. /// 顶部提示栏的显示状态
  71. /// </summary>
  72. public Visibility TipVisible
  73. {
  74. get { return tipVisible; }
  75. set
  76. {
  77. SetProperty(ref tipVisible, value);
  78. }
  79. }
  80. private Visibility readModelTip = Visibility.Collapsed;
  81. public Visibility ReadModelTip
  82. {
  83. get { return readModelTip; }
  84. set
  85. {
  86. SetProperty(ref readModelTip, value);
  87. }
  88. }
  89. /// <summary>
  90. /// 底部工具栏 RegionName
  91. /// </summary>
  92. public string BottomToolRegionName { get; set; }
  93. private bool _isInPageEdit = false;
  94. /// <summary>
  95. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  96. /// </summary>
  97. public bool isInPageEdit
  98. {
  99. get { return _isInPageEdit; }
  100. set
  101. {
  102. _isInPageEdit = value;
  103. if (!value)
  104. {
  105. CanRedo = PDFViewer.UndoManager.CanRedo;
  106. CanUndo = PDFViewer.UndoManager.CanUndo;
  107. }
  108. }
  109. }
  110. public Action PageEditUndo { get; set; }
  111. public Action PageEditRedo { get; set; }
  112. /// <summary>
  113. ///工具条
  114. ///0:收起
  115. ///40:显示
  116. /// </summary>
  117. private int toolRowHeight = 40;
  118. public int ToolRowHeight
  119. {
  120. get { return toolRowHeight; }
  121. set
  122. {
  123. SetProperty(ref toolRowHeight, value);
  124. }
  125. }
  126. /// <summary>
  127. /// 水印,背景侧边栏宽度
  128. /// 0:收起
  129. /// 260:显示
  130. /// </summary>
  131. private int propertyColumnWidth = 0;
  132. public int PropertyColumnWidth
  133. {
  134. get { return propertyColumnWidth; }
  135. set
  136. {
  137. SetProperty(ref propertyColumnWidth, value);
  138. }
  139. }
  140. private int gridToolRow = 1;
  141. /// <summary>
  142. /// 控制ToolContent的Row
  143. /// </summary>
  144. public int GridToolRow
  145. {
  146. get { return gridToolRow; }
  147. set
  148. {
  149. SetProperty(ref gridToolRow, value);
  150. }
  151. }
  152. private int gridToolRowSpan = 3;
  153. /// <summary>
  154. /// 控制ToolContent的RowSpan
  155. /// </summary>
  156. public int GridToolRowSpan
  157. {
  158. get { return gridToolRowSpan; }
  159. set
  160. {
  161. SetProperty(ref gridToolRowSpan, value);
  162. }
  163. }
  164. private Visibility toolContentVisible = Visibility.Collapsed;
  165. /// <summary>
  166. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  167. /// 留意:显示前需要先注入内容、设置好行和跨行数
  168. /// </summary>
  169. public Visibility ToolContentVisible
  170. {
  171. get { return toolContentVisible; }
  172. set
  173. {
  174. SetProperty(ref toolContentVisible, value);
  175. }
  176. }
  177. private Visibility gridVisibility = Visibility.Visible;
  178. /// <summary>
  179. /// 是否正在加载中
  180. /// </summary>
  181. public Visibility GridVisibility
  182. {
  183. get { return gridVisibility; }
  184. set
  185. {
  186. SetProperty(ref gridVisibility, value);
  187. }
  188. }
  189. private Visibility isLoading = Visibility.Collapsed;
  190. private Visibility ocrContentVisible = Visibility.Collapsed;
  191. public Visibility OCRContentVisible
  192. {
  193. get { return ocrContentVisible; }
  194. set
  195. {
  196. SetProperty(ref ocrContentVisible, value);
  197. }
  198. }
  199. /// <summary>
  200. /// 是否正在加载中
  201. /// </summary>
  202. public Visibility IsLoading
  203. {
  204. get { return isLoading; }
  205. set
  206. {
  207. SetProperty(ref isLoading, value);
  208. }
  209. }
  210. private Visibility converterBarContentVisible = Visibility.Collapsed;
  211. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  212. /// <summary>
  213. /// 控制ToolsBarContent的显示
  214. /// 留意:显示前需要先注入内容、设置好行和跨行数
  215. /// </summary>
  216. public Visibility ConverterBarContentVisible
  217. {
  218. get { return converterBarContentVisible; }
  219. set
  220. {
  221. SetProperty(ref converterBarContentVisible, value);
  222. }
  223. }
  224. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  225. /// <summary>
  226. /// 控制ToolsBarContent的显示
  227. /// 留意:显示前需要先注入内容、设置好行和跨行数
  228. /// </summary>
  229. public Visibility ToolsBarContentVisible
  230. {
  231. get { return toolsBarContentVisible; }
  232. set
  233. {
  234. SetProperty(ref toolsBarContentVisible, value);
  235. }
  236. }
  237. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  238. /// <summary>
  239. /// 控制ToolsBarContent的显示
  240. /// 留意:显示前需要先注入内容、设置好行和跨行数
  241. /// </summary>
  242. public Visibility TextEditToolContentVisible
  243. {
  244. get { return textEditToolContentVisible; }
  245. set
  246. {
  247. SetProperty(ref textEditToolContentVisible, value);
  248. }
  249. }
  250. private bool isPorpertyOpen = false;
  251. /// <summary>
  252. /// 属性栏是否展开
  253. /// </summary>
  254. public bool IsPropertyOpen
  255. {
  256. get { return isPorpertyOpen; }
  257. set
  258. {
  259. SetProperty(ref isPorpertyOpen, value);
  260. }
  261. }
  262. private Visibility isReadMode = Visibility.Visible;
  263. /// <summary>
  264. ///是否为阅读模式
  265. /// </summary>
  266. public Visibility IsReadMode
  267. {
  268. get { return isReadMode; }
  269. set
  270. {
  271. SetProperty(ref isReadMode, value);
  272. }
  273. }
  274. private bool canSave;
  275. /// <summary>
  276. /// 是否可以保存
  277. /// </summary>
  278. public bool CanSave
  279. {
  280. get { return canSave; }
  281. set
  282. {
  283. SetProperty(ref canSave, value);
  284. }
  285. }
  286. private bool canUndo;
  287. /// <summary>
  288. /// 是否可以进行Undo
  289. /// </summary>
  290. public bool CanUndo
  291. {
  292. get { return canUndo; }
  293. set
  294. {
  295. SetProperty(ref canUndo, value);
  296. }
  297. }
  298. private bool canRedo;
  299. /// <summary>
  300. /// 是否可以进行Redo
  301. /// </summary>
  302. public bool CanRedo
  303. {
  304. get { return canRedo; }
  305. set
  306. {
  307. SetProperty(ref canRedo, value);
  308. }
  309. }
  310. private GridLength botaWidth = new GridLength(48);
  311. /// <summary>
  312. /// BOTA栏的宽度
  313. /// </summary>
  314. public GridLength BOTAWidth
  315. {
  316. get { return botaWidth; }
  317. set
  318. {
  319. SetProperty(ref botaWidth, value);
  320. if (botaWidth.Value <= 48)
  321. {
  322. OpenBOTA = false;
  323. }
  324. }
  325. }
  326. private int selectedIndex;
  327. /// <summary>
  328. /// 工具栏选中项的索引
  329. /// </summary>
  330. public int TabSelectedIndex
  331. {
  332. get { return selectedIndex; }
  333. set
  334. {
  335. SetProperty(ref selectedIndex, value);
  336. }
  337. }
  338. private bool openBOTA = false;
  339. /// <summary>
  340. /// 是否展开BOTA
  341. /// </summary>
  342. public bool OpenBOTA
  343. {
  344. get { return openBOTA; }
  345. set
  346. {
  347. openBOTA = value;
  348. if (openBOTA && BOTAWidth.Value <= 48)
  349. {
  350. BOTAWidth = new GridLength(256);
  351. }
  352. }
  353. }
  354. private Dictionary<string, string> regionNameByTabItem;
  355. private Dictionary<string, string> barContentByTabItem;
  356. private string previousBar = "";
  357. public string CurrentBar = "";
  358. public string unicode = null;
  359. /// <summary>
  360. /// 用来避免重复触发导航事件的标志符
  361. /// </summary>
  362. private bool isOpenFile = false;
  363. /// <summary>
  364. /// 鼠标滚轮缩放的缩放值
  365. /// </summary>
  366. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  367. /// <summary>
  368. /// 注释-链接,提示语
  369. /// </summary>
  370. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  371. public Visibility LinkAnnotTipVisibility
  372. {
  373. get { return linkAnnotTipVisibility; }
  374. set
  375. {
  376. SetProperty(ref linkAnnotTipVisibility, value);
  377. }
  378. }
  379. private string linkAnnotTipText = "Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range";
  380. private bool isCreateLink = false;
  381. public string LinkAnnotTipText
  382. {
  383. get { return linkAnnotTipText; }
  384. set
  385. {
  386. SetProperty(ref linkAnnotTipText, value);
  387. }
  388. }
  389. #endregion 属性、变量
  390. #region 命令
  391. public DelegateCommand LoadFile { get; set; }
  392. public DelegateCommand Load { get; set; }
  393. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  394. public DelegateCommand SaveFile { get; set; }
  395. public DelegateCommand SaveAsFile { get; set; }
  396. public DelegateCommand SaveAsFlattenCommand { get; set; }
  397. public DelegateCommand UndoCommand { get; set; }
  398. public DelegateCommand RedoCommand { get; set; }
  399. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  400. public DelegateCommand PrintCommand { get; set; }
  401. public DelegateCommand SettingsCommand { get; set; }
  402. public DelegateCommand ShareCommand { get; set; }
  403. public DelegateCommand<object> CreateLinkCommand { get; set; }
  404. public DelegateCommand PropertyCommand { get; set; }
  405. public DelegateCommand ShowInFolderCommand { get; set; }
  406. #endregion 命令
  407. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  408. {
  409. region = regionManager;
  410. dialogs = dialogService;
  411. events = eventAggregator;
  412. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  413. LoadFile = new DelegateCommand(loadFile);
  414. Load = new DelegateCommand(LoadControl);
  415. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  416. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  417. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  418. UndoCommand = new DelegateCommand(Undo);
  419. RedoCommand = new DelegateCommand(Redo);
  420. ShareCommand = new DelegateCommand(share);
  421. PropertyCommand = new DelegateCommand(property);
  422. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  423. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  424. ViwerRegionName = RegionNames.ViwerRegionName;
  425. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  426. BOTARegionName = RegionNames.BOTARegionName;
  427. PropertyRegionName = RegionNames.PropertyRegionName;
  428. BottomToolRegionName = RegionNames.BottomToolRegionName;
  429. ReadModeRegionName = RegionNames.ReadModeRegionName;
  430. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  431. PrintCommand = new DelegateCommand(ShowPrintDialog);
  432. SettingsCommand = new DelegateCommand(SettingsEvent);
  433. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  434. //未显示时无法注册上Region名称
  435. ToolContentVisible = Visibility.Visible;
  436. ToolsBarContentVisible = Visibility.Visible;
  437. OCRContentVisible = Visibility.Visible;
  438. TipVisible = Visibility.Visible;
  439. TipContentRegionName = RegionNames.TipContentRegionName;
  440. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  441. ToolContentRegionName = Guid.NewGuid().ToString();
  442. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  443. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  444. TextEditContentRegionName = Guid.NewGuid().ToString();
  445. ToolContentVisible = Visibility.Collapsed;
  446. ToolsBarContentVisible = Visibility.Collapsed;
  447. OCRContentVisible = Visibility.Collapsed;
  448. TipVisible = Visibility.Collapsed;
  449. regionNameByTabItem = new Dictionary<string, string>();
  450. barContentByTabItem = new Dictionary<string, string>();
  451. InitialregionNameByTabItem(ref regionNameByTabItem);
  452. InitialbarContentByTabItem(ref barContentByTabItem);
  453. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  454. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  455. //TODO:根据缓存 选择用户上次选择的菜单
  456. EnterSelectedBar("TabItemAnnotation");
  457. }
  458. /// <summary>
  459. /// 设置Tip状态栏的显示状态
  460. /// </summary>
  461. /// <param name="show">是否显示</param>
  462. public void ShowTip(bool show)
  463. {
  464. if (show)
  465. {
  466. TipVisible = Visibility.Visible;
  467. }
  468. else
  469. {
  470. TipVisible = Visibility.Collapsed;
  471. }
  472. }
  473. /// <summary>
  474. /// 右键菜单创建链接
  475. /// </summary>
  476. /// <param name="obj"></param>
  477. private void CreateLinkEvent(object obj)
  478. {
  479. if (obj is object[] objArry)
  480. {
  481. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  482. {
  483. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  484. linkArgs.URI = string.Empty;
  485. linkArgs.LinkType = LINK_TYPE.GOTO;
  486. linkArgs.PageIndex = annotCommand.PageIndex;
  487. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  488. this.IsRightMenuCreateLink = true;
  489. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  490. lists.Add(linkArgs);
  491. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  492. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  493. PDFViewer.SetToolParam(annotArgs);
  494. this.IsPropertyOpen = true;
  495. }
  496. }
  497. }
  498. /// <summary>
  499. /// 在文件资源管理器中显示
  500. /// </summary>
  501. private void ShowInFolder()
  502. {
  503. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  504. }
  505. private void property()
  506. {
  507. DialogParameters valuePairs = new DialogParameters();
  508. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  509. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  510. }
  511. private void share()
  512. {
  513. try
  514. {
  515. var path = PDFViewer.Document.FilePath;
  516. string subject = "分享至" + " " + PDFViewer.Document.FileName;
  517. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  518. }
  519. catch
  520. {
  521. AlertsMessage alertsMessage = new AlertsMessage();
  522. alertsMessage.ShowDialog("", "未检测到Ooutlook软件,请先安装Outlook", "OK");
  523. }
  524. }
  525. private void SettingsEvent()
  526. {
  527. dialogs.ShowDialog(DialogNames.SettingsDialog, null, null);
  528. }
  529. private bool CanSaveExcute()
  530. {
  531. return CanSave;
  532. }
  533. private void MenuEnterReadModeEvent(object obj)
  534. {
  535. }
  536. public void ShowPrintDialog()
  537. {
  538. DialogParameters printValue = new DialogParameters();
  539. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  540. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  541. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  542. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  543. }
  544. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  545. {
  546. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  547. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  548. //其他工具菜单栏共用一个ToolsBarContentRegionName
  549. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  550. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  551. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  552. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  553. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  554. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  555. }
  556. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  557. {
  558. dictionary.Add("TabItemPageEdit", "PageEditContent");
  559. dictionary.Add("TabItemTool", "ToolsBarContent");
  560. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  561. dictionary.Add("TabItemConvert", "ConverterBarContent");
  562. dictionary.Add("TabItemScan", "ScanContent");
  563. dictionary.Add("TabItemEdit", "TextEditToolContent");
  564. dictionary.Add("TabItemForm", "FormsToolContent");
  565. dictionary.Add("TabItemFill", "FillAndSignContent");
  566. }
  567. private void UpdateShowContent(string currentBar)
  568. {
  569. ToolContentVisible = Visibility.Collapsed;
  570. ToolsBarContentVisible = Visibility.Collapsed;
  571. ConverterBarContentVisible = Visibility.Collapsed;
  572. TextEditToolContentVisible = Visibility.Collapsed;
  573. OCRContentVisible = Visibility.Collapsed;
  574. switch (currentBar)
  575. {
  576. case "TabItemAnnotation":
  577. case "TabItemTool":
  578. case "TabItemForm":
  579. case "TabItemFill":
  580. ToolsBarContentVisible = Visibility.Visible;
  581. break;
  582. case "TabItemScan":
  583. ToolsBarContentVisible = Visibility.Visible;
  584. OCRContentVisible = Visibility.Visible;
  585. break;
  586. case "TabItemEdit":
  587. TextEditToolContentVisible = Visibility.Visible;
  588. break;
  589. case "TabItemConvert":
  590. ConverterBarContentVisible = Visibility.Visible;
  591. break;
  592. case "TabItemPageEdit":
  593. case "HeaderFooterContent":
  594. case "BatesContent":
  595. case "WatermarkContent":
  596. case "BackgroundContent":
  597. case "RedactionContent":
  598. ToolContentVisible = Visibility.Visible;
  599. break;
  600. default:
  601. break;
  602. }
  603. PDFEditMode(currentBar);
  604. FormMode(currentBar);
  605. }
  606. private void PDFEditMode(string currentBar)
  607. {
  608. if (currentBar == "TabItemEdit")
  609. {
  610. if (PDFViewer != null)
  611. {
  612. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  613. //SelectedPrpoertyPanel("TextEditProperty", null);
  614. //IsPropertyOpen = true;
  615. }
  616. }
  617. else
  618. {
  619. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  620. {
  621. IsPropertyOpen = false;
  622. PDFViewer.SetMouseMode(MouseModes.PanTool);
  623. }
  624. }
  625. }
  626. private void FormMode(string currentBar)
  627. {
  628. if (currentBar == "TabItemForm")
  629. {
  630. if (PDFViewer != null)
  631. {
  632. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  633. }
  634. }
  635. else
  636. {
  637. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  638. {
  639. PDFViewer.SetMouseMode(MouseModes.PanTool);
  640. }
  641. }
  642. }
  643. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  644. {
  645. if (!isInPageEdit)
  646. {
  647. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  648. //页面编辑模式下,按钮状态根据页面编辑的undo redo来显示
  649. if (e.PropertyName == "CanUndo")
  650. {
  651. CanUndo = PDFViewer.UndoManager.CanUndo;
  652. }
  653. if (e.PropertyName == "CanRedo")
  654. {
  655. CanRedo = PDFViewer.UndoManager.CanRedo;
  656. }
  657. }
  658. if (e.PropertyName == "CanSave")
  659. {
  660. CanSave = PDFViewer.UndoManager.CanSave;
  661. }
  662. }
  663. /// <summary>
  664. /// 选项卡切换事件
  665. /// </summary>
  666. /// <param name="e"></param>
  667. private void TabControlSelectonChangedEvent(object e)
  668. {
  669. var args = e as SelectionChangedEventArgs;
  670. if (args != null)
  671. {
  672. var item = args.AddedItems[0] as TabItem;
  673. CurrentBar = item.Name;
  674. if (previousBar != CurrentBar)
  675. {
  676. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  677. {
  678. EnterToolMode(barContentByTabItem[CurrentBar]);
  679. isInPageEdit = true;
  680. }
  681. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  682. {
  683. EnterSelectedBar(CurrentBar);
  684. isInPageEdit = false;
  685. }
  686. previousBar = CurrentBar;
  687. }
  688. }
  689. }
  690. /// <summary>
  691. /// 阅读模式
  692. /// </summary>
  693. /// <param name="viewContent"></param>
  694. public async void RbtnReadMode()
  695. {
  696. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  697. App.IsBookMode = true;
  698. IsLoading = Visibility.Visible;
  699. await Task.Delay(1);
  700. NavigationParameters param = new NavigationParameters();
  701. param.Add(ParameterNames.PDFViewer, PDFViewer);
  702. param.Add(ParameterNames.ViewContentViewModel, this);
  703. region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  704. //ShowContent(CurrentBar, true);
  705. if (GridToolRow != 0)
  706. {
  707. GridToolRow = 0;
  708. }
  709. if (GridToolRowSpan != 4)
  710. {
  711. GridToolRowSpan = 4;
  712. }
  713. //isInPageEdit = true;
  714. UpdateShowContent("TabItemPageEdit");
  715. IsLoading = Visibility.Collapsed;
  716. }
  717. /// <summary>
  718. /// 退出阅读模式
  719. /// </summary>
  720. public async void UnReadModel()
  721. {
  722. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  723. App.IsBookMode = false;
  724. IsLoading = Visibility.Visible;
  725. await Task.Delay(1);
  726. //PDFViewer.MouseMode = MouseModes.None;
  727. if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  728. {
  729. if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  730. {
  731. var contentRegion = region.Regions[ViwerRegionName];
  732. contentRegion.Remove(PDFViewer);
  733. }
  734. region.AddToRegion(ViwerRegionName, PDFViewer);
  735. }
  736. if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  737. {
  738. EnterSelectedBar("TabItemAnnotation");
  739. }
  740. else
  741. {
  742. EnterSelectedBar(CurrentBar);
  743. }
  744. //isInPageEdit = false;
  745. //ShowContent(CurrentBar, false);
  746. //isInPageEdit = false;
  747. IsLoading = Visibility.Collapsed;
  748. ReadModelTip = Visibility.Visible;
  749. await Task.Delay(3000);
  750. ReadModelTip = Visibility.Collapsed;
  751. }
  752. #region PDFViewer鼠标滚轮缩放事件
  753. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  754. {
  755. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  756. PDFViewer.Zoom(newZoom);
  757. }
  758. public double CheckZoomLevel(double zoom, bool IsGrowth)
  759. {
  760. double standardZoom = 100;
  761. if (zoom <= 0.01)
  762. {
  763. return 0.01;
  764. }
  765. if (zoom >= 10)
  766. {
  767. return 10;
  768. }
  769. zoom *= 100;
  770. for (int i = 0; i < zoomLevel.Length - 1; i++)
  771. {
  772. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  773. {
  774. standardZoom = zoomLevel[i + 1];
  775. break;
  776. }
  777. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  778. {
  779. standardZoom = zoomLevel[i];
  780. break;
  781. }
  782. }
  783. return standardZoom / 100;
  784. }
  785. #endregion PDFViewer鼠标滚轮缩放事件
  786. #region Navigate
  787. public void OnNavigatedTo(NavigationContext navigationContext)
  788. {
  789. if (isOpenFile)
  790. return;
  791. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  792. if (mainVM != null)
  793. {
  794. mainViewModel = mainVM;
  795. mainViewModel.viewContentViewModel = this;
  796. }
  797. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  798. if (pdfview != null)
  799. {
  800. PDFViewer = pdfview;
  801. if(pdfview.Tag!=null)
  802. {
  803. //保存密码
  804. PassWord = pdfview.Tag.ToString();
  805. }
  806. loadFile();
  807. }
  808. isOpenFile = true;
  809. }
  810. public bool IsNavigationTarget(NavigationContext navigationContext)
  811. {
  812. return false;
  813. }
  814. public void OnNavigatedFrom(NavigationContext navigationContext)
  815. {
  816. }
  817. #endregion Navigate
  818. #region 方法
  819. /// <summary>
  820. /// 视图面板 切换分屏模式
  821. /// </summary>
  822. /// <param name="mode"></param>
  823. public void EnterSplitMode(SplitMode mode)
  824. {
  825. ///通知UI层更改布局
  826. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  827. }
  828. private void Undo()
  829. {
  830. if (isInPageEdit)
  831. {
  832. //执行页面编辑的Undo
  833. PageEditUndo?.Invoke();
  834. }
  835. else
  836. {
  837. PDFViewer.UndoManager.Undo();
  838. }
  839. }
  840. private void Redo()
  841. {
  842. if (isInPageEdit)
  843. {
  844. //执行页面编辑的Redo
  845. PageEditRedo?.Invoke();
  846. }
  847. else
  848. {
  849. PDFViewer.UndoManager.Redo();
  850. }
  851. }
  852. private void LoadControl()
  853. {
  854. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  855. // 非必要情况不要使用该异步方法,可能会导致一次性加载多个文件时出现因异步引起的regionname 错乱问题
  856. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  857. // {
  858. NavigationParameters parameters = new NavigationParameters();
  859. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  860. parameters.Add(ParameterNames.ViewContentViewModel, this);
  861. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  862. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  863. region.RequestNavigate(ReadModeRegionName, "ReadModeContent", parameters);
  864. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  865. //TODO 根据上一次关闭记录的菜单,选中TabItem
  866. EnterSelectedBar("TabItemAnnotation");
  867. //}
  868. //));
  869. }
  870. /// <summary>
  871. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  872. /// </summary>
  873. /// <param name="Content"></param>
  874. /// <param name="annotPropertyPanel"></param>
  875. public void SelectedPrpoertyPanel(string Content, AnnotPropertyPanel annotPropertyPanel)
  876. {
  877. NavigationParameters parameters = new NavigationParameters();
  878. //传其他参数:文档类,空注释面板;
  879. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  880. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  881. parameters.Add(ParameterNames.ViewContentViewModel, this);
  882. region.RequestNavigate(PropertyRegionName, Content, parameters);
  883. }
  884. /// <summary>
  885. /// 将PDFViwer添加到Region
  886. /// </summary>
  887. private void loadFile()
  888. {
  889. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  890. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  891. CanSave = PDFViewer.UndoManager.CanSave;
  892. CanUndo = PDFViewer.UndoManager.CanUndo;
  893. CanRedo = PDFViewer.UndoManager.CanRedo;
  894. region.AddToRegion(ViwerRegionName, PDFViewer);
  895. }
  896. /// <summary>
  897. /// 已有路径文档的保存逻辑
  898. /// </summary>
  899. public bool saveFile()
  900. {
  901. try
  902. {
  903. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  904. return saveAsFile();
  905. //文档已被修复时 提示另存为
  906. if (PDFViewer.Document.HasRepaired)
  907. {
  908. AlertsMessage alertsMessage = new AlertsMessage();
  909. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  910. if (alertsMessage.result == ContentResult.Ok)
  911. return saveAsFile();
  912. else
  913. return false;
  914. }
  915. //文件路径无法存在时
  916. if (!File.Exists(PDFViewer.Document.FilePath))
  917. {
  918. AlertsMessage alertsMessage = new AlertsMessage();
  919. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  920. if (alertsMessage.result == ContentResult.Ok)
  921. return saveAsFile();
  922. else
  923. return false;
  924. }
  925. //只读文件无法写入时,提示另存为
  926. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  927. if (fileInfo.IsReadOnly)
  928. {
  929. AlertsMessage alertsMessage = new AlertsMessage();
  930. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  931. if (alertsMessage.result == ContentResult.Ok)
  932. return saveAsFile();
  933. else
  934. return false;
  935. }
  936. bool result = PDFViewer.Document.WriteToLoadedPath();
  937. if (result)
  938. {
  939. PDFViewer.UndoManager.CanSave = false;
  940. App.Current.Dispatcher.Invoke(() =>
  941. {
  942. //保存时更新缩略图
  943. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  944. try
  945. {
  946. if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  947. {
  948. var size = PDFViewer.Document.GetPageSize(0);
  949. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  950. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  951. if (File.Exists(folderPath))
  952. File.Delete(folderPath);
  953. DirectoryInfo folder = new DirectoryInfo(folderPath);
  954. if (!folder.Exists)
  955. folder.Create();
  956. string imagePath = info.ThumbImgPath;
  957. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  958. {
  959. string imageName = Guid.NewGuid().ToString();
  960. imagePath = System.IO.Path.Combine(folderPath, imageName);
  961. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  962. {
  963. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  964. }
  965. }
  966. else
  967. {
  968. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  969. {
  970. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  971. }
  972. }
  973. info.ThumbImgPath = imagePath;
  974. SettingHelper.SetFileInfo(info);
  975. }
  976. }
  977. catch
  978. {
  979. info.ThumbImgPath = null;
  980. SettingHelper.SetFileInfo(info);
  981. }
  982. });
  983. }
  984. else
  985. {
  986. //文件被占用 保存失败时
  987. AlertsMessage alertsMessage = new AlertsMessage();
  988. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  989. if (alertsMessage.result == ContentResult.Ok)
  990. return saveAsFile();
  991. else
  992. return false;
  993. }
  994. return result;
  995. }
  996. catch { return false; }
  997. }
  998. /// <summary>
  999. /// 另存为或新文档保存逻辑
  1000. /// </summary>
  1001. public bool saveAsFile(Action RedactionAction = null)
  1002. {
  1003. var dlg = new Microsoft.Win32.SaveFileDialog();
  1004. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1005. dlg.FileName = PDFViewer.Document.FileName;
  1006. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1007. {
  1008. bool result = false;
  1009. if (RedactionAction != null)
  1010. {
  1011. //保存前进行标记密文处理应用或擦除
  1012. RedactionAction.Invoke();
  1013. }
  1014. if (App.OpenedFileList.Contains(dlg.FileName))
  1015. {
  1016. //提示文件已经被打开
  1017. }
  1018. else
  1019. {
  1020. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  1021. if (result)
  1022. {
  1023. DoAfterSaveAs(dlg.FileName);
  1024. }
  1025. else
  1026. {
  1027. //提示文件被其他软件占用 无法保存
  1028. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  1029. }
  1030. ;
  1031. }
  1032. return result;
  1033. }
  1034. else
  1035. return false;
  1036. }
  1037. /// <summary>
  1038. /// 另存为Flatten
  1039. /// </summary>
  1040. private void saveAsFlatten()
  1041. {
  1042. var dlg = new SaveFileDialog();
  1043. dlg.Filter = Properties.Resources.OpenDialogFilter;
  1044. dlg.FileName = PDFViewer.Document.FileName.Substring(0, PDFViewer.Document.FileName.LastIndexOf(".")) + "_Flatten.pdf";
  1045. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  1046. {
  1047. saveFile();
  1048. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FileName);
  1049. if (kmdoc == null)
  1050. return;
  1051. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  1052. if (result)
  1053. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  1054. kmdoc.Release();
  1055. }
  1056. }
  1057. /// <summary>
  1058. /// 另存为后进行的操作
  1059. /// 重新打开新文档
  1060. /// </summary>
  1061. /// <param name="targetPath"></param>
  1062. public void DoAfterSaveAs(string targetPath)
  1063. {
  1064. App.OpenedFileList.Remove(targetPath);
  1065. string oldFilePath = targetPath;
  1066. PDFViewer.UndoManager.CanSave = false;
  1067. mainViewModel.OpenFile(targetPath);
  1068. //TODO:通知各模块更新PDFview对象
  1069. //var result = OpenFile(targetPath, true);
  1070. //if (result)
  1071. //{
  1072. // FileChanged.Invoke(this, null);
  1073. // Zoomer.PdfViewer = PdfViewer;
  1074. // PageSelector.PdfViewer = PdfViewer;
  1075. // ViewModeSelector.PdfViewer = PdfViewer;
  1076. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  1077. // if (fileInfo != null)
  1078. // {
  1079. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  1080. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  1081. // if (fileInfo.LastFitMode == FitMode.FitFree)
  1082. // PdfViewer.Zoom(fileInfo.LastZoom);
  1083. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  1084. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  1085. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  1086. // else
  1087. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  1088. // }
  1089. //}
  1090. }
  1091. /// <summary>
  1092. /// 显示前添加内容到Region
  1093. /// </summary>
  1094. /// <param name="isPageEdit"></param>
  1095. private void ShowContent(string currentBar, bool isToolMode = false)
  1096. {
  1097. GridVisibility = Visibility.Visible;
  1098. //显示页面编辑或其他工具
  1099. if (currentBar == "TabItemPageEdit" || isToolMode)
  1100. {
  1101. if (currentBar == "TabItemPageEdit")//进入页面编辑
  1102. {
  1103. if (GridToolRow != 1)
  1104. {
  1105. GridToolRow = 1;
  1106. }
  1107. if (GridToolRowSpan != 3)
  1108. {
  1109. GridToolRowSpan = 3;
  1110. }
  1111. }
  1112. else//进入水印等其他工具模式
  1113. {
  1114. GridVisibility = Visibility.Collapsed;
  1115. if (GridToolRow != 0)
  1116. {
  1117. GridToolRow = 0;
  1118. }
  1119. if (GridToolRowSpan != 4)
  1120. {
  1121. GridToolRowSpan = 4;
  1122. }
  1123. }
  1124. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  1125. UpdateShowContent(currentBar);
  1126. }
  1127. else
  1128. {
  1129. if (GridToolRow != 1)
  1130. {
  1131. GridToolRow = 1;
  1132. }
  1133. UpdateShowContent(currentBar);
  1134. }
  1135. }
  1136. /// <summary>
  1137. /// 从二级工具栏进入需要修改界面布局的场景
  1138. /// </summary>
  1139. /// <param name="EditToolName"></param>
  1140. private void EnterEditTools(StringWithUnicode EditToolName)
  1141. {
  1142. EnterSelectedEditTool(EditToolName);
  1143. }
  1144. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  1145. {
  1146. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  1147. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  1148. {
  1149. PDFViewer.Document.ReleasePages();
  1150. PDFViewer.ReloadDocument();
  1151. }
  1152. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  1153. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1154. {
  1155. region.AddToRegion(ViwerRegionName, PDFViewer);
  1156. }
  1157. CurrentBar = "TabItemTool";
  1158. EnterSelectedBar(CurrentBar);
  1159. }
  1160. /// <summary>
  1161. /// 二级菜单指定目标处理
  1162. /// </summary>
  1163. /// <param name="e"></param>
  1164. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  1165. {
  1166. CurrentBar = EditToolName.EditToolsContentName;
  1167. EnterToolMode(CurrentBar);
  1168. }
  1169. /// <summary>
  1170. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  1171. /// </summary>
  1172. /// <param name="targetToolMode">要导航过去的控件名称</param>
  1173. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  1174. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  1175. {
  1176. IsLoading = Visibility.Visible;
  1177. await Task.Delay(3);
  1178. NavigationParameters param = new NavigationParameters();
  1179. if (valuePairs == null)
  1180. {
  1181. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1182. param.Add(ParameterNames.ViewContentViewModel, this);
  1183. }
  1184. else//有传入其他内容的参数时
  1185. {
  1186. param = valuePairs;
  1187. }
  1188. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  1189. ShowContent(CurrentBar, true);
  1190. IsLoading = Visibility.Collapsed;
  1191. }
  1192. private void EnterSelectedBar(string currentBar)
  1193. {
  1194. NavigationParameters param = new NavigationParameters();
  1195. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1196. param.Add(ParameterNames.ViewContentViewModel, this);
  1197. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  1198. if (currentBar == "TabItemScan")
  1199. {
  1200. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  1201. }
  1202. ShowContent(currentBar);
  1203. }
  1204. /// <summary>
  1205. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  1206. /// </summary>
  1207. public void ExitToolMode()
  1208. {
  1209. ToolContentVisible = Visibility.Collapsed;
  1210. if (isInPageEdit)
  1211. {
  1212. TabSelectedIndex = 0;
  1213. isInPageEdit = false;
  1214. }
  1215. }
  1216. #endregion 方法
  1217. }
  1218. }