CPDFLocationControl.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.Controls.Common
  18. {
  19. /// <summary>
  20. /// Interaction logic for CPDFLocationControl.xaml
  21. /// </summary>
  22. public partial class CPDFLocationControl : UserControl, INotifyPropertyChanged
  23. {
  24. public static readonly DependencyProperty SelectedTagIndexProperty =
  25. DependencyProperty.Register("SelectedTagIndex", typeof(int), typeof(CPDFLocationControl), new PropertyMetadata(4));
  26. public int SelectedTagIndex
  27. {
  28. get { return (int)GetValue(SelectedTagIndexProperty) ; }
  29. set
  30. {
  31. SetValue(SelectedTagIndexProperty, value);
  32. }
  33. }
  34. private int _selectedTag;
  35. public int SelectedTag
  36. {
  37. get => _selectedTag;
  38. set
  39. {
  40. if(UpdateProper(ref _selectedTag, value))
  41. {
  42. SelectedTagIndex = value;
  43. }
  44. }
  45. }
  46. private string _horizOffsetValue = "0";
  47. public string HorizOffsetValue
  48. {
  49. get => _horizOffsetValue;
  50. set
  51. {
  52. if (string.IsNullOrEmpty(value) )
  53. {
  54. return;
  55. }
  56. if (int.Parse(value) > XNumericControl.Maximum)
  57. {
  58. value = XNumericControl.Maximum.ToString();
  59. }
  60. if (int.Parse(value) < XNumericControl.Minimum)
  61. {
  62. value = XNumericControl.Minimum.ToString();
  63. }
  64. if (UpdateProper(ref _horizOffsetValue, value))
  65. {
  66. HorizOffsetChanged?.Invoke(this, EventArgs.Empty);
  67. }
  68. }
  69. }
  70. private string _vertOffsetValue = "0";
  71. public string VertOffsetValue
  72. {
  73. get => _vertOffsetValue;
  74. set
  75. {
  76. if (string.IsNullOrEmpty(value))
  77. {
  78. return;
  79. }
  80. if (int.Parse(value) > YNumericControl.Maximum)
  81. {
  82. value = YNumericControl.Maximum.ToString();
  83. }
  84. if (int.Parse(value) < YNumericControl.Minimum)
  85. {
  86. value = YNumericControl.Minimum.ToString();
  87. }
  88. if ( !string.IsNullOrEmpty(value) && UpdateProper(ref _vertOffsetValue, value))
  89. {
  90. VertOffsetChanged?.Invoke(this, EventArgs.Empty);
  91. }
  92. }
  93. }
  94. public event EventHandler HorizOffsetChanged;
  95. public event EventHandler VertOffsetChanged;
  96. public CPDFLocationControl()
  97. {
  98. InitializeComponent();
  99. DataContext = this;
  100. }
  101. public event PropertyChangedEventHandler PropertyChanged;
  102. protected virtual void OnPropertyChanged(string propertyName = null)
  103. {
  104. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  105. }
  106. protected bool UpdateProper<T>(ref T properValue,
  107. T newValue,
  108. [CallerMemberName] string properName = "")
  109. {
  110. if (object.Equals(properValue, newValue))
  111. return false;
  112. properValue = newValue;
  113. OnPropertyChanged(properName);
  114. return true;
  115. }
  116. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  117. {
  118. }
  119. }
  120. }