ViewContentViewModel.cs 48 KB

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