SplitDialogViewModel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.HomePageToolsDialogs;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
  15. {
  16. public class SplitDialogViewModel : BindableBase, IDialogAware
  17. {
  18. public string Title => "";
  19. private CPDFViewer pdfViewer;
  20. private double pageCount;
  21. //页面总数
  22. public double PageCount
  23. {
  24. get { return pageCount; }
  25. set
  26. {
  27. SetProperty(ref pageCount, value);
  28. }
  29. }
  30. private string customPageText;
  31. /// <summary>
  32. /// 自定义的输入内容
  33. /// </summary>
  34. public string CustomPageText
  35. {
  36. get { return customPageText; }
  37. set
  38. {
  39. SetProperty(ref customPageText, value);
  40. }
  41. }
  42. private HomePageSplitDialogModel model;
  43. public HomePageSplitDialogModel Model
  44. {
  45. get { return model; }
  46. set
  47. {
  48. SetProperty(ref model, value);
  49. }
  50. }
  51. public event Action<IDialogResult> RequestClose;
  52. public DelegateCommand CancelCommand { get; set; }
  53. public DelegateCommand SplitCommnad { get; set; }
  54. public SplitDialogViewModel()
  55. {
  56. CancelCommand = new DelegateCommand(cancel);
  57. SplitCommnad = new DelegateCommand(split);
  58. Model = new HomePageSplitDialogModel();
  59. }
  60. private void cancel()
  61. {
  62. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  63. }
  64. private void split()
  65. {
  66. List<int> pages = new List<int>();
  67. Model.PageRange = customPageText;
  68. DialogParameters valuePairs = new DialogParameters();
  69. valuePairs.Add(ParameterNames.DataModel,Model);
  70. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  71. }
  72. #region
  73. public bool CanCloseDialog()
  74. {
  75. return true;
  76. }
  77. public void OnDialogClosed()
  78. {
  79. }
  80. public void OnDialogOpened(IDialogParameters parameters)
  81. {
  82. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer,out pdfViewer);
  83. if(pdfViewer!=null)
  84. {
  85. PageCount = pdfViewer.Document.PageCount;
  86. Model.SourceFileName = System.IO.Path.GetFileName(pdfViewer.Document.FileName);
  87. }
  88. }
  89. #endregion
  90. }
  91. }