CPDFRotationControl.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. int result = 0;
  35. if (int.TryParse(value, out result))
  36. {
  37. if (result > NumericUpDownControl.Maximum)
  38. {
  39. value = NumericUpDownControl.Maximum.ToString();
  40. }
  41. if (result < NumericUpDownControl.Minimum)
  42. {
  43. value = NumericUpDownControl.Minimum.ToString();
  44. }
  45. if (UpdateProper(ref _rotationText, value))
  46. {
  47. RotationChanged?.Invoke(this, EventArgs.Empty);
  48. }
  49. }
  50. }
  51. }
  52. public event EventHandler RotationChanged;
  53. public CPDFRotationControl()
  54. {
  55. InitializeComponent();
  56. DataContext = this;
  57. }
  58. private void RotationBtn_Click(object sender, RoutedEventArgs e)
  59. {
  60. var btn = sender as Button;
  61. if (btn != null)
  62. {
  63. if (btn.Name == "CounterclockwiseBtn")
  64. {
  65. RotationText = (int.Parse(RotationText) - 45).ToString();
  66. }
  67. else if (btn.Name == "ResetBtn")
  68. {
  69. RotationText = "0";
  70. }
  71. else if (btn.Name == "ClockwiseBtn")
  72. {
  73. RotationText = (int.Parse(RotationText) + 45).ToString();
  74. }
  75. }
  76. }
  77. public event PropertyChangedEventHandler PropertyChanged;
  78. protected virtual void OnPropertyChanged(string propertyName = null)
  79. {
  80. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  81. }
  82. protected bool UpdateProper<T>(ref T properValue,
  83. T newValue,
  84. [CallerMemberName] string properName = "")
  85. {
  86. if (object.Equals(properValue, newValue))
  87. return false;
  88. properValue = newValue;
  89. OnPropertyChanged(properName);
  90. return true;
  91. }
  92. }
  93. }