CPDFViewModeControl.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using ComPDFKitViewer;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using static ComPDFKit.Controls.PDFControlUI.CPDFViewModeUI;
  7. namespace ComPDFKit.Controls.PDFControl
  8. {
  9. public partial class CPDFViewModeControl : UserControl
  10. {
  11. public PDFViewControl ViewControl;
  12. public event EventHandler<SplitMode> SplitModeChanged;
  13. public string CurrentContinuousMode = "Continuous";
  14. public string CurrentViewMode = "Single";
  15. public Dictionary<Tuple<string, string>, ViewMode> GetViewMode = new Dictionary<Tuple<string, string>, ViewMode>();
  16. public CPDFViewModeControl()
  17. {
  18. InitializeComponent();
  19. CPDFViewModeUI.Loaded += CPDFViewModeUI_Loaded;
  20. }
  21. public void InitWithPDFViewer(PDFViewControl viewControl)
  22. {
  23. this.ViewControl = viewControl;
  24. CPDFViewModeUI.SetContinuousEvent -= CPDFViewModeUI_SetContinuousEvent;
  25. CPDFViewModeUI.SetViewModeEvent -= CPDFViewModeUI_SetViewModeEvent;
  26. CPDFViewModeUI.SplitModeChanged -= CPDFViewModeUI_SplitModeChanged;
  27. CPDFViewModeUI.SetContinuousEvent += CPDFViewModeUI_SetContinuousEvent;
  28. CPDFViewModeUI.SetViewModeEvent += CPDFViewModeUI_SetViewModeEvent;
  29. CPDFViewModeUI.SplitModeChanged += CPDFViewModeUI_SplitModeChanged;
  30. }
  31. private void CPDFViewModeUI_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. GetViewMode.Clear();
  34. GetViewMode.Add(Tuple.Create("Continuous", "Single"), ViewMode.SingleContinuous);
  35. GetViewMode.Add(Tuple.Create("Continuous", "Double"), ViewMode.DoubleContinuous);
  36. GetViewMode.Add(Tuple.Create("Continuous", "Book"), ViewMode.BookContinuous);
  37. GetViewMode.Add(Tuple.Create("Discontinuous", "Single"), ViewMode.Single);
  38. GetViewMode.Add(Tuple.Create("Discontinuous", "Double"), ViewMode.Double);
  39. GetViewMode.Add(Tuple.Create("Discontinuous", "Book"), ViewMode.Book);
  40. }
  41. private void CPDFViewModeUI_SplitModeChanged(object sender, SplitMode e)
  42. {
  43. SplitModeChanged.Invoke(this, e);
  44. }
  45. private void CPDFViewModeUI_SetContinuousEvent(object sender, string e)
  46. {
  47. CurrentContinuousMode = (sender as RadioButton).Tag as string;
  48. if (ViewControl != null && ViewControl.PDFViewTool != null)
  49. {
  50. CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
  51. pdfViewer?.SetViewMode(GetViewMode[Tuple.Create(CurrentContinuousMode, CurrentViewMode)]);
  52. }
  53. }
  54. private void CPDFViewModeUI_SetViewModeEvent(object sender, string e)
  55. {
  56. CurrentViewMode = (sender as RadioButton).Tag as string;
  57. if (ViewControl != null && ViewControl.PDFViewTool != null)
  58. {
  59. CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
  60. pdfViewer?.SetViewMode(GetViewMode[Tuple.Create(CurrentContinuousMode, CurrentViewMode)]);
  61. }
  62. }
  63. }
  64. }