SplitDialogViewModel.cs 2.8 KB

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