TextEditToolContentViewModel.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Media;
  9. using System.Windows;
  10. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  11. using System.Windows.Controls;
  12. using Prism.Regions;
  13. using ComPDFKitViewer.PdfViewer;
  14. using PDF_Office.Model;
  15. using Microsoft.Win32;
  16. using PDF_Office.CustomControl;
  17. namespace PDF_Office.ViewModels.Tools
  18. {
  19. public class TextEditToolContentViewModel: BindableBase, INavigationAware
  20. {
  21. #region Command
  22. public DelegateCommand<object> AddContentCommand { get; set; }
  23. #endregion
  24. public TextEditToolContentViewModel()
  25. {
  26. InitCommand();
  27. }
  28. private void InitCommand()
  29. {
  30. AddContentCommand = new DelegateCommand<object>(AddContent);
  31. }
  32. public void AddContent(object obj)
  33. {
  34. if (PDFViewer == null || obj == null || obj as CustomIconToggleBtn == null) return;
  35. var btn = obj as CustomIconToggleBtn;
  36. if(btn.IsChecked == true)
  37. {
  38. if (btn.Tag.ToString() == "Text")
  39. {
  40. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
  41. }
  42. else
  43. {
  44. OpenFileDialog openFileDialog = new OpenFileDialog();
  45. openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
  46. openFileDialog.Multiselect = true;
  47. if ((bool)openFileDialog.ShowDialog())
  48. {
  49. if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
  50. {
  51. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  52. PDFViewer.AddPDFEditImage(openFileDialog.FileName);
  53. }
  54. }
  55. btn.IsChecked = false;
  56. }
  57. }
  58. else
  59. {
  60. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  61. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  62. }
  63. }
  64. public void OnNavigatedTo(NavigationContext navigationContext)
  65. {
  66. }
  67. public bool IsNavigationTarget(NavigationContext navigationContext)
  68. {
  69. return true;
  70. }
  71. private CPDFViewer PDFViewer;
  72. public void OnNavigatedFrom(NavigationContext navigationContext)
  73. {
  74. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  75. if (PDFViewer != null)
  76. {
  77. }
  78. }
  79. }
  80. }