CPDFRotationControl.xaml.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  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.Common
  18. {
  19. /// <summary>
  20. /// Interaction logic for CPDFRotationControl.xaml
  21. /// </summary>
  22. public partial class CPDFRotationControl : UserControl, INotifyPropertyChanged
  23. {
  24. private string _rotationText = "0";
  25. public string RotationText
  26. {
  27. get => _rotationText;
  28. set
  29. {
  30. if (string.IsNullOrEmpty(value))
  31. {
  32. return;
  33. }
  34. if (int.Parse(value) > NumericUpDownControl.Maxium)
  35. {
  36. value = NumericUpDownControl.Maxium.ToString();
  37. }
  38. if (int.Parse(value) < NumericUpDownControl.Minimum)
  39. {
  40. value = NumericUpDownControl.Minimum.ToString();
  41. }
  42. if (UpdateProper(ref _rotationText, value))
  43. {
  44. RotationChanged?.Invoke(this, EventArgs.Empty);
  45. }
  46. }
  47. }
  48. public event EventHandler RotationChanged;
  49. public CPDFRotationControl()
  50. {
  51. InitializeComponent();
  52. DataContext = this;
  53. }
  54. private void RotationBtn_Click(object sender, RoutedEventArgs e)
  55. {
  56. var btn = sender as Button;
  57. if (btn != null)
  58. {
  59. if (btn.Name == "CounterclockwiseBtn")
  60. {
  61. RotationText = (int.Parse(RotationText) + 45).ToString();
  62. }
  63. else if (btn.Name == "ResetBtn")
  64. {
  65. RotationText = "0";
  66. }
  67. else if (btn.Name == "ClockwiseBtn")
  68. {
  69. RotationText = (int.Parse(RotationText) - 45).ToString();
  70. }
  71. }
  72. }
  73. public event PropertyChangedEventHandler PropertyChanged;
  74. protected virtual void OnPropertyChanged(string propertyName = null)
  75. {
  76. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  77. }
  78. protected bool UpdateProper<T>(ref T properValue,
  79. T newValue,
  80. [CallerMemberName] string properName = "")
  81. {
  82. if (object.Equals(properValue, newValue))
  83. return false;
  84. properValue = newValue;
  85. OnPropertyChanged(properName);
  86. return true;
  87. }
  88. }
  89. }