ToolsBarContentViewModel.cs 2.7 KB

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