ViewContentViewModel.cs 26 KB

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