TextEditToolContentViewModel.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. private CPDFViewer PDFViewer;
  65. public void OnNavigatedTo(NavigationContext navigationContext)
  66. {
  67. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  68. if (PDFViewer != null)
  69. {
  70. }
  71. }
  72. public bool IsNavigationTarget(NavigationContext navigationContext)
  73. {
  74. return true;
  75. }
  76. public void OnNavigatedFrom(NavigationContext navigationContext)
  77. {
  78. }
  79. }
  80. }