ViewContentViewModel.cs 27 KB

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