CPDFScalingControl.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using compdfkit_tools.Common;
  2. using ComPDFKitViewer.PdfViewer;
  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;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace compdfkit_tools.PDFControl
  18. {
  19. /// <summary>
  20. /// PDFScallingControl.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class CPDFScalingControl : UserControl
  23. {
  24. public CPDFViewer pdfViewer;
  25. public CPDFScalingControl()
  26. {
  27. InitializeComponent();
  28. CPDFScalingUI.Loaded += PDFScalingControl_Loaded;
  29. }
  30. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  31. {
  32. this.pdfViewer = pdfViewer;
  33. }
  34. private void PDFScalingControl_Loaded(object sender, RoutedEventArgs e)
  35. {
  36. CPDFScalingUI.SetScaleEvent += PDFScalingControl_SetScaleEvent;
  37. CPDFScalingUI.ScaleIncreaseEvent += PDFScalingControl_ScaleIncreaseEvent;
  38. CPDFScalingUI.ScaleDecreaseEvent += PDFScalingControl_ScaleDecreaseEvent;
  39. CPDFScalingUI.SetPresetScaleEvent += CPDFScalingUI_SetPresetScaleEvent;
  40. }
  41. private void PDFScalingControl_ScaleDecreaseEvent(object sender, EventArgs e)
  42. {
  43. if (pdfViewer == null || pdfViewer.Document == null)
  44. {
  45. return;
  46. }
  47. CPDFScalingUI.Scale -= 10;
  48. pdfViewer.Zoom((double)(CPDFScalingUI.Scale) / 100);
  49. }
  50. private void PDFScalingControl_ScaleIncreaseEvent(object sender, EventArgs e)
  51. {
  52. if (pdfViewer == null || pdfViewer.Document == null)
  53. {
  54. return;
  55. }
  56. CPDFScalingUI.Scale += 10;
  57. pdfViewer.Zoom((double)(CPDFScalingUI.Scale) / 100);
  58. }
  59. private void PDFScalingControl_SetScaleEvent(object sender, string e)
  60. {
  61. if (pdfViewer == null || pdfViewer.Document == null)
  62. {
  63. return;
  64. }
  65. if (!string.IsNullOrEmpty(e))
  66. {
  67. pdfViewer.Zoom(double.Parse(e) / 100);
  68. }
  69. }
  70. private void CPDFScalingUI_SetPresetScaleEvent(object sender, string e)
  71. {
  72. if (pdfViewer == null || pdfViewer.Document == null)
  73. {
  74. return;
  75. }
  76. pdfViewer.Zoom(double.Parse(e) / 100);
  77. }
  78. }
  79. }