ViewContentViewModel.cs 26 KB

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