ToolsBarContentViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Security.Cryptography.X509Certificates;
  13. namespace PDF_Office.ViewModels.Tools
  14. {
  15. public class ToolsBarContentViewModel : BindableBase,INavigationAware
  16. {
  17. private CPDFViewer PDFViewer;
  18. private ViewContentViewModel viewContentViewModel;
  19. public IDialogService dialogs;
  20. public IEventAggregator eventAggregator;
  21. /// <summary>
  22. /// 是否是第一次加载
  23. /// </summary>
  24. private bool isFirstLoad = true;
  25. public DelegateCommand CompressCommand { get; set; }
  26. public DelegateCommand SetPasswordCommand { get; set; }
  27. public DelegateCommand CancelPasswordCommand { get; set; }
  28. public DelegateCommand<object> SetEditToolsCommand { get; set; }
  29. public DelegateCommand SetWatermarkCommand { get; set; }
  30. public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
  31. {
  32. dialogs= dialogService;
  33. this.eventAggregator= eventAggregator;
  34. CompressCommand = new DelegateCommand(OpenCompressDialog);
  35. SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
  36. CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
  37. SetEditToolsCommand = new DelegateCommand<object>(SetEditTools);
  38. }
  39. private void SetEditTools(object e)
  40. {
  41. var args = e as System.Windows.Controls.Button;
  42. if (args != null)
  43. {
  44. this.eventAggregator.GetEvent<EditToolsEvent>().Publish(args.Name);
  45. }
  46. }
  47. private void OpenCompressDialog()
  48. {
  49. DialogParameters value = new DialogParameters();
  50. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  51. dialogs.ShowDialog(DialogNames.CompressDialog, value, e => { });
  52. }
  53. private void OpenSetPasswordDialog()
  54. {
  55. DialogParameters value = new DialogParameters();
  56. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  57. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
  58. }
  59. private void OpenCancelPasswordDialog()
  60. {
  61. DialogParameters value = new DialogParameters();
  62. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  63. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  64. }
  65. public bool IsNavigationTarget(NavigationContext navigationContext)
  66. {
  67. return true;
  68. }
  69. public void OnNavigatedFrom(NavigationContext navigationContext)
  70. {
  71. }
  72. public void OnNavigatedTo(NavigationContext navigationContext)
  73. {
  74. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  75. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  76. if (PDFViewer != null)
  77. {
  78. isFirstLoad = false;
  79. }
  80. }
  81. }
  82. }