ViewContentViewModel.cs 26 KB

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