ScanViwer.xaml.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using PDF_Office.CustomControl.ScanViewControl;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace PDF_Office.Views.Scan
  17. {
  18. /// <summary>
  19. /// ScanViwer.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class ScanViwer : UserControl
  22. {
  23. public ScanViwer()
  24. {
  25. InitializeComponent();
  26. }
  27. double scale = 1;
  28. private void Grid_MouseWheel(object sender, MouseWheelEventArgs e)
  29. {
  30. if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
  31. {
  32. if (e.Delta > 0)
  33. {
  34. scale += 0.1;
  35. ImageGrid.Width = 500* scale;
  36. ImageGrid.Height = 500 * scale;
  37. }
  38. else
  39. {
  40. if (scale > 0.2)
  41. {
  42. scale -= 0.2;
  43. }
  44. ImageGrid.Width = 500* scale;
  45. ImageGrid.Height = 500 * scale;
  46. }
  47. }
  48. RedressControl.Visibility = Visibility.Collapsed;
  49. }
  50. private Point MouseDownPos;
  51. private async void CustomPanel_MouseDown(object sender, MouseButtonEventArgs e)
  52. {
  53. RedressControl.Visibility = Visibility.Visible;
  54. MouseDownPos = e.GetPosition(BitmapPanel);
  55. HitTestResult hitResult = VisualTreeHelper.HitTest(BitmapPanel, MouseDownPos);
  56. if (hitResult != null && hitResult.VisualHit is CustomDraw)
  57. {
  58. CustomDraw hitChild = (CustomDraw)hitResult.VisualHit;
  59. BitmapPanel.DisplayContent(hitChild);
  60. RedressControl.SetValue(Canvas.LeftProperty, hitChild.PaintRect.Left + (hitChild.PaintRect.Width / 2 - RedressControl.ActualWidth / 2));
  61. if (hitChild.PaintRect.Top - RedressControl.ActualHeight > 0)
  62. {
  63. RedressControl.SetValue(Canvas.TopProperty, hitChild.PaintRect.Top - RedressControl.ActualHeight);
  64. }
  65. else
  66. {
  67. RedressControl.SetValue(Canvas.TopProperty, hitChild.PaintRect.Bottom);
  68. }
  69. RedressControl.HitChild = hitChild;
  70. RedressControl.TextBoxContext = hitChild.PaintText;
  71. await Task.Delay(5);
  72. RedressControl.SelectAll();
  73. return;
  74. }
  75. RedressControl.Visibility = Visibility.Collapsed;
  76. }
  77. private void RedressControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  78. {
  79. if (!(bool)e.NewValue)
  80. {
  81. BitmapPanel.DisplayContent(null);
  82. }
  83. }
  84. private void RedressControl_ApplyCommandHandler(object sender, EventArgs e)
  85. {
  86. RedressControl.HitChild.PaintText = RedressControl.TextBoxContext;
  87. RedressControl.HitChild.Draw();
  88. RedressControl.Visibility = Visibility.Collapsed;
  89. }
  90. }
  91. }