ViewContentViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. namespace PDF_Office.ViewModels
  20. {
  21. public class ViewContentViewModel : BindableBase, INavigationAware
  22. {
  23. #region 属性、变量
  24. private CPDFViewer PDFViewer { get; set; }
  25. private MainContentViewModel mainViewModel { get; set; }
  26. public IRegionManager region;
  27. public IDialogService dialogs;
  28. public string ViwerRegionName { get; set; }
  29. public string BOTARegionName { get; set; }
  30. public string PropertyRegionName { get; set; }
  31. public string ToolContentRegionName { get; set; }
  32. public string ToolsBarContentRegionName { get; set; }
  33. public string ConverterBarContentRegionName { get; set; }
  34. /// <summary>
  35. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  36. /// </summary>
  37. public bool isInPageEdit = false;
  38. public Action PageEditUndo { get; set; }
  39. public Action PageEditRedo { get; set; }
  40. private int gridToolRow = 1;
  41. /// <summary>
  42. /// 控制ToolContent的Row
  43. /// </summary>
  44. public int GridToolRow
  45. {
  46. get { return gridToolRow; }
  47. set
  48. {
  49. SetProperty(ref gridToolRow, value);
  50. }
  51. }
  52. private int gridToolRowSpan = 3;
  53. /// <summary>
  54. /// 控制ToolContent的RowSpan
  55. /// </summary>
  56. public int GridToolRowSpan
  57. {
  58. get { return gridToolRowSpan; }
  59. set
  60. {
  61. SetProperty(ref gridToolRowSpan, value);
  62. }
  63. }
  64. private Visibility toolContentVisible = Visibility.Collapsed;
  65. /// <summary>
  66. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  67. /// 留意:显示前需要先注入内容、设置好行和跨行数
  68. /// </summary>
  69. public Visibility ToolContentVisible
  70. {
  71. get { return toolContentVisible; }
  72. set
  73. {
  74. SetProperty(ref toolContentVisible, value);
  75. }
  76. }
  77. private Visibility isLoading = Visibility.Collapsed;
  78. /// <summary>
  79. /// 是否正在加载中
  80. /// </summary>
  81. public Visibility IsLoading
  82. {
  83. get { return isLoading; }
  84. set
  85. {
  86. SetProperty(ref isLoading, value);
  87. }
  88. }
  89. private Visibility converterBarContentVisible = Visibility.Collapsed;
  90. /// <summary>
  91. /// 控制ToolsBarContent的显示
  92. /// 留意:显示前需要先注入内容、设置好行和跨行数
  93. /// </summary>
  94. public Visibility ConverterBarContentVisible
  95. {
  96. get { return converterBarContentVisible; }
  97. set
  98. {
  99. SetProperty(ref converterBarContentVisible, value);
  100. }
  101. }
  102. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  103. /// <summary>
  104. /// 控制ToolsBarContent的显示
  105. /// 留意:显示前需要先注入内容、设置好行和跨行数
  106. /// </summary>
  107. public Visibility ToolsBarContentVisible
  108. {
  109. get { return toolsbarContentVisible; }
  110. set
  111. {
  112. SetProperty(ref toolsbarContentVisible, value);
  113. }
  114. }
  115. private bool canSave;
  116. /// <summary>
  117. /// 是否可以保存
  118. /// </summary>
  119. public bool CanSave
  120. {
  121. get { return canSave; }
  122. set
  123. {
  124. SetProperty(ref canSave, value);
  125. }
  126. }
  127. private bool canUndo;
  128. public bool CanUndo
  129. {
  130. get { return canUndo; }
  131. set
  132. {
  133. SetProperty(ref canUndo, value);
  134. }
  135. }
  136. private bool canRedo;
  137. public bool CanRedo
  138. {
  139. get { return canRedo; }
  140. set
  141. {
  142. SetProperty(ref canRedo, value);
  143. }
  144. }
  145. private Dictionary<string, string> regionNameByTabItem;
  146. private Dictionary<string, string> barContentByTabItem;
  147. private string previousBar = "";
  148. private string currentBar = "";
  149. /// <summary>
  150. /// 用来避免重复触发导航事件的标志符
  151. /// </summary>
  152. private bool isOpenFile = false;
  153. /// <summary>
  154. /// 鼠标滚轮缩放的缩放值
  155. /// </summary>
  156. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  157. #endregion
  158. #region 命令
  159. public DelegateCommand LoadFile { get; set; }
  160. public DelegateCommand Load { get; set; }
  161. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  162. public DelegateCommand SaveFile { get; set; }
  163. public DelegateCommand SaveAsFile { get; set; }
  164. public DelegateCommand UndoCommand { get; set; }
  165. public DelegateCommand RedoCommand { get; set; }
  166. #endregion
  167. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  168. {
  169. region = regionManager;
  170. dialogs = dialogService;
  171. LoadFile = new DelegateCommand(loadFile);
  172. Load = new DelegateCommand(LoadControl);
  173. SaveFile = new DelegateCommand(()=> { saveFile(); });
  174. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  175. UndoCommand = new DelegateCommand(Undo);
  176. RedoCommand = new DelegateCommand(Redo);
  177. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  178. ViwerRegionName = Guid.NewGuid().ToString();
  179. BOTARegionName = Guid.NewGuid().ToString();
  180. PropertyRegionName = Guid.NewGuid().ToString();
  181. //未显示时无法注册上Region名称
  182. ToolContentVisible = Visibility.Visible;
  183. ToolContentRegionName = Guid.NewGuid().ToString();
  184. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  185. ConverterBarContentRegionName = Guid.NewGuid().ToString();
  186. ToolContentVisible = Visibility.Collapsed;
  187. ToolsBarContentVisible = Visibility.Collapsed;
  188. regionNameByTabItem = new Dictionary<string, string>();
  189. barContentByTabItem = new Dictionary<string, string>();
  190. InitialregionNameByTabItem(ref regionNameByTabItem);
  191. InitialbarContentByTabItem(ref barContentByTabItem);
  192. }
  193. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  194. {
  195. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  196. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  197. //其他工具菜单栏共用一个ToolsBarContentRegionName
  198. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  199. dictionary.Add("TabItemConvert", ConverterBarContentRegionName);
  200. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  201. dictionary.Add("TabItemEdit", ToolsBarContentRegionName);
  202. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  203. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  204. }
  205. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  206. {
  207. dictionary.Add("TabItemPageEdit", "PageEditContent");
  208. dictionary.Add("TabItemTool", "ToolsBarContent");
  209. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  210. dictionary.Add("TabItemConvert", "ConverterBarContent");
  211. dictionary.Add("TabItemScan", "");
  212. dictionary.Add("TabItemEdit", "");
  213. dictionary.Add("TabItemForm", "");
  214. dictionary.Add("TabItemFill", "");
  215. }
  216. private void UpdateShowContent(string currentBar) {
  217. ToolContentVisible = Visibility.Collapsed;
  218. ToolsBarContentVisible = Visibility.Collapsed;
  219. ConverterBarContentVisible = Visibility.Collapsed;
  220. switch (currentBar) {
  221. case "TabItemTool":
  222. ToolsBarContentVisible = Visibility.Visible;
  223. break;
  224. case "TabItemConvert":
  225. ConverterBarContentVisible = Visibility.Visible;
  226. break;
  227. case "TabItemPageEdit":
  228. ToolContentVisible = Visibility.Visible;
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  235. {
  236. if (e.PropertyName == "CanSave")
  237. {
  238. CanSave = PDFViewer.UndoManager.CanSave;
  239. }
  240. if(e.PropertyName == "CanUndo")
  241. {
  242. CanUndo = PDFViewer.UndoManager.CanUndo;
  243. }
  244. if(e.PropertyName =="CanRedo")
  245. {
  246. CanRedo = PDFViewer.UndoManager.CanRedo;
  247. }
  248. }
  249. /// <summary>
  250. /// 选项卡切换事件
  251. /// </summary>
  252. /// <param name="e"></param>
  253. private void TabControlSelectonChangedEvent(object e)
  254. {
  255. var args = e as SelectionChangedEventArgs;
  256. if (args != null)
  257. {
  258. var item = args.AddedItems[0] as TabItem;
  259. currentBar = item.Name;
  260. if (previousBar != currentBar)
  261. {
  262. if(currentBar== "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  263. {
  264. EnterToolMode(barContentByTabItem[currentBar]);
  265. isInPageEdit = true;
  266. }
  267. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  268. {
  269. EnterSelectedBar(currentBar);
  270. isInPageEdit = false;
  271. }
  272. previousBar = currentBar;
  273. }
  274. }
  275. }
  276. #region PDFViewer鼠标滚轮缩放事件
  277. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  278. {
  279. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  280. PDFViewer.Zoom(newZoom);
  281. }
  282. private double CheckZoomLevel(double zoom, bool IsGrowth)
  283. {
  284. double standardZoom = 100;
  285. if (zoom <= 0.01)
  286. {
  287. return 0.01;
  288. }
  289. if (zoom >= 10)
  290. {
  291. return 10;
  292. }
  293. zoom *= 100;
  294. for (int i = 0; i < zoomLevel.Length - 1; i++)
  295. {
  296. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  297. {
  298. standardZoom = zoomLevel[i + 1];
  299. break;
  300. }
  301. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  302. {
  303. standardZoom = zoomLevel[i];
  304. break;
  305. }
  306. }
  307. return standardZoom / 100;
  308. }
  309. #endregion
  310. #region Navigate
  311. public void OnNavigatedTo(NavigationContext navigationContext)
  312. {
  313. if (isOpenFile)
  314. return;
  315. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  316. if (mainVM != null)
  317. {
  318. mainViewModel = mainVM;
  319. }
  320. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  321. if (pdfview != null)
  322. {
  323. PDFViewer = pdfview;
  324. loadFile();
  325. }
  326. isOpenFile = true;
  327. }
  328. public bool IsNavigationTarget(NavigationContext navigationContext)
  329. {
  330. return true;
  331. }
  332. public void OnNavigatedFrom(NavigationContext navigationContext)
  333. {
  334. }
  335. #endregion
  336. #region 方法
  337. private void Undo()
  338. {
  339. if(isInPageEdit)
  340. {
  341. //执行页面编辑的Undo
  342. PageEditUndo?.Invoke();
  343. }
  344. else
  345. {
  346. PDFViewer.UndoManager.Undo();
  347. }
  348. }
  349. private void Redo()
  350. {
  351. if(isInPageEdit)
  352. {
  353. //执行页面编辑的Redo
  354. PageEditRedo?.Invoke();
  355. }
  356. else
  357. {
  358. PDFViewer.UndoManager.Redo();
  359. }
  360. }
  361. private void LoadControl()
  362. {
  363. //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
  364. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  365. {
  366. NavigationParameters parameters = new NavigationParameters();
  367. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  368. parameters.Add(ParameterNames.ViewContentViewModel, this);
  369. region.RequestNavigate(BOTARegionName, "BOTAContent",parameters);
  370. }
  371. ));
  372. }
  373. /// <summary>
  374. /// 将PDFViwer添加到Region
  375. /// </summary>
  376. private void loadFile()
  377. {
  378. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  379. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  380. CanSave = PDFViewer.UndoManager.CanSave;
  381. CanUndo = PDFViewer.UndoManager.CanUndo;
  382. CanRedo = PDFViewer.UndoManager.CanRedo;
  383. region.AddToRegion(ViwerRegionName, PDFViewer);
  384. }
  385. /// <summary>
  386. /// 已有路径文档的保存逻辑
  387. /// </summary>
  388. private bool saveFile()
  389. {
  390. try
  391. {
  392. if (string.IsNullOrEmpty(PDFViewer.Document.FilePath))
  393. return saveAsFile();
  394. //文档已被修复时 提示另存为
  395. if (PDFViewer.Document.HasRepaired)
  396. {
  397. AlertsMessage alertsMessage = new AlertsMessage();
  398. alertsMessage.ShowDialog("", "文件已被修复,建议另存为", "Cancel", "OK");
  399. if (alertsMessage.result == ContentResult.Ok)
  400. return saveAsFile();
  401. else
  402. return false;
  403. }
  404. //文件路径无法存在时
  405. if (!File.Exists(PDFViewer.Document.FilePath))
  406. {
  407. AlertsMessage alertsMessage = new AlertsMessage();
  408. alertsMessage.ShowDialog("", "文件路径不存在,需要另存为", "Cancel", "OK");
  409. if (alertsMessage.result == ContentResult.Ok)
  410. return saveAsFile();
  411. else
  412. return false;
  413. }
  414. //只读文件无法写入时,提示另存为
  415. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  416. if (fileInfo.IsReadOnly)
  417. {
  418. AlertsMessage alertsMessage = new AlertsMessage();
  419. alertsMessage.ShowDialog("", "文件为只读文件,需要另存为", "Cancel", "OK");
  420. if (alertsMessage.result == ContentResult.Ok)
  421. return saveAsFile();
  422. else
  423. return false;
  424. }
  425. bool result = PDFViewer.Document.WriteToLoadedPath();
  426. if (result)
  427. {
  428. PDFViewer.UndoManager.CanSave = false;
  429. App.Current.Dispatcher.Invoke(() =>
  430. {
  431. //TODO:更新缩略图
  432. //OpenFileInfo info = SettingHelper.GetFileInfo(PdfViewer.Document.FilePath);
  433. //try
  434. //{
  435. // if (!string.IsNullOrEmpty(info.ThumbImgPath) && !PdfViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  436. // {
  437. // var size = PdfViewer.Document.GetPageSize(0);
  438. // System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PdfViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  439. // string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  440. // if (File.Exists(folderPath))
  441. // File.Delete(folderPath);
  442. // DirectoryInfo folder = new DirectoryInfo(folderPath);
  443. // if (!folder.Exists)
  444. // folder.Create();
  445. // string imagePath = info.ThumbImgPath;
  446. // if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  447. // {
  448. // string imageName = Guid.NewGuid().ToString();
  449. // imagePath = System.IO.Path.Combine(folderPath, imageName);
  450. // using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  451. // {
  452. // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  453. // }
  454. // }
  455. // else
  456. // {
  457. // using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  458. // {
  459. // bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  460. // }
  461. // }
  462. // info.ThumbImgPath = imagePath;
  463. // SettingHelper.SetFileInfo(info);
  464. // }
  465. //}
  466. //catch
  467. //{
  468. // info.ThumbImgPath = null;
  469. // SettingHelper.SetFileInfo(info);
  470. //}
  471. });
  472. }
  473. else
  474. {
  475. //文件被占用 保存失败时
  476. AlertsMessage alertsMessage = new AlertsMessage();
  477. alertsMessage.ShowDialog("", "文件被占用,需要另存为", "Cancel", "OK");
  478. if (alertsMessage.result == ContentResult.Ok)
  479. return saveAsFile();
  480. else
  481. return false;
  482. }
  483. return result;
  484. }
  485. catch { return false; }
  486. }
  487. /// <summary>
  488. /// 另存为或新文档保存逻辑
  489. /// </summary>
  490. private bool saveAsFile()
  491. {
  492. var dlg = new SaveFileDialog();
  493. dlg.Filter = Properties.Resources.OpenDialogFilter;
  494. dlg.FileName = PDFViewer.Document.FileName;
  495. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  496. {
  497. bool result = false;
  498. if (App.OpenedFileList.Contains(dlg.FileName))
  499. {
  500. //提示文件已经被打开
  501. }
  502. else
  503. {
  504. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  505. if (result)
  506. {
  507. DoAfterSaveAs(dlg.FileName);
  508. }
  509. else
  510. {
  511. //提示文件被其他软件占用 无法保存
  512. //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") })
  513. }
  514. ;
  515. }
  516. return result;
  517. }
  518. else
  519. return false;
  520. }
  521. /// <summary>
  522. /// 另存为后进行的操作
  523. /// 重新打开新文档
  524. /// </summary>
  525. /// <param name="targetPath"></param>
  526. public void DoAfterSaveAs(string targetPath)
  527. {
  528. App.OpenedFileList.Remove(targetPath);
  529. string oldFilePath = targetPath;
  530. PDFViewer.UndoManager.CanSave = false;
  531. mainViewModel.OpenFile(targetPath);
  532. //TODO:通知各模块更新PDFview对象
  533. //var result = OpenFile(targetPath, true);
  534. //if (result)
  535. //{
  536. // FileChanged.Invoke(this, null);
  537. // Zoomer.PdfViewer = PdfViewer;
  538. // PageSelector.PdfViewer = PdfViewer;
  539. // ViewModeSelector.PdfViewer = PdfViewer;
  540. // OpenFileInfo fileInfo = SettingHelper.GetFileInfo(oldFilePath);
  541. // if (fileInfo != null)
  542. // {
  543. // PdfViewer.ChangeViewMode(fileInfo.LastViewMode);
  544. // PdfViewer.ChangeFitMode(fileInfo.LastFitMode);
  545. // if (fileInfo.LastFitMode == FitMode.FitFree)
  546. // PdfViewer.Zoom(fileInfo.LastZoom);
  547. // PdfViewer.GoToPage(fileInfo.LastPageIndex);
  548. // if (fileInfo.LastDrawMode == DrawModes.Draw_Mode_Custom && fileInfo.LastFillColor != 0)
  549. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode, fileInfo.LastFillColor);
  550. // else
  551. // PdfViewer.SetDrawMode(fileInfo.LastDrawMode);
  552. // }
  553. //}
  554. }
  555. /// <summary>
  556. /// 显示前添加内容到Region
  557. /// </summary>
  558. /// <param name="isPageEdit"></param>
  559. private void ShowContent(string currentBar,bool isToolMode=false)
  560. {
  561. //显示页面编辑或其他工具
  562. if (currentBar == "TabItemPageEdit"||isToolMode)
  563. {
  564. if (currentBar == "TabItemPageEdit")//进入页面编辑
  565. {
  566. if (GridToolRow != 1)
  567. {
  568. GridToolRow = 1;
  569. }
  570. if (GridToolRowSpan != 3)
  571. {
  572. GridToolRowSpan = 3;
  573. }
  574. }
  575. else//进入水印等其他工具模式
  576. {
  577. if (GridToolRow != 0)
  578. {
  579. GridToolRow = 0;
  580. }
  581. if (GridToolRowSpan != 4)
  582. {
  583. GridToolRowSpan = 4;
  584. }
  585. }
  586. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  587. UpdateShowContent(currentBar);
  588. }
  589. else
  590. {
  591. if (GridToolRow != 1)
  592. {
  593. GridToolRow = 1;
  594. }
  595. UpdateShowContent(currentBar);
  596. }
  597. }
  598. /// <summary>
  599. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  600. /// </summary>
  601. /// <param name="targetToolMode">要导航过去的控件名称</param>
  602. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  603. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  604. {
  605. IsLoading = Visibility.Visible;
  606. await Task.Delay(3);
  607. NavigationParameters param = new NavigationParameters();
  608. if (valuePairs == null)
  609. {
  610. param.Add(ParameterNames.PDFViewer, PDFViewer);
  611. param.Add(ParameterNames.ViewContentViewModel, this);
  612. }
  613. else//有传入其他内容的参数时
  614. {
  615. param = valuePairs;
  616. }
  617. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  618. ShowContent(currentBar,true);
  619. IsLoading = Visibility.Collapsed;
  620. }
  621. private void EnterSelectedBar(string currentBar)
  622. {
  623. NavigationParameters param = new NavigationParameters();
  624. param.Add(ParameterNames.PDFViewer, PDFViewer);
  625. param.Add(ParameterNames.ViewContentViewModel, this);
  626. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  627. ShowContent(currentBar);
  628. }
  629. /// <summary>
  630. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  631. /// </summary>
  632. public void ExitToolMode()
  633. {
  634. ToolContentVisible = Visibility.Collapsed;
  635. }
  636. #endregion
  637. }
  638. }