CPDFTileControl.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 CPDFTileControl.xaml
  21. /// </summary>
  22. public partial class CPDFTileControl : UserControl, INotifyPropertyChanged
  23. {
  24. private bool _fullScreen = false;
  25. public bool IsFullScreen
  26. {
  27. get => _fullScreen;
  28. set
  29. {
  30. if (UpdateProper(ref _fullScreen, value))
  31. {
  32. FullScreenChanged?.Invoke(this, EventArgs.Empty);
  33. }
  34. }
  35. }
  36. private string _verticalSpacingValue = "0";
  37. public string VerticalSpacingValue
  38. {
  39. get => _verticalSpacingValue;
  40. set
  41. {
  42. if (string.IsNullOrEmpty(value))
  43. {
  44. return;
  45. }
  46. if (int.Parse(value) > VerticalNumericControl.Maximum)
  47. {
  48. value = VerticalNumericControl.Maximum.ToString();
  49. }
  50. if (int.Parse(value) < VerticalNumericControl.Minimum)
  51. {
  52. value = VerticalNumericControl.Minimum.ToString();
  53. }
  54. if (!string.IsNullOrEmpty(value) && UpdateProper(ref _verticalSpacingValue, value))
  55. {
  56. VerticalSpacingChanged?.Invoke(this, EventArgs.Empty);
  57. }
  58. }
  59. }
  60. private string _horizontalSpacingValue = "0";
  61. public string HorizontalSpacingValue
  62. {
  63. get => _horizontalSpacingValue;
  64. set
  65. {
  66. if (string.IsNullOrEmpty(value))
  67. {
  68. return;
  69. }
  70. if (int.Parse(value) > HorizontalNumericControl.Maximum)
  71. {
  72. value = VerticalNumericControl.Maximum.ToString();
  73. }
  74. if (int.Parse(value) < HorizontalNumericControl.Minimum)
  75. {
  76. value = HorizontalNumericControl.Minimum.ToString();
  77. }
  78. if (!string.IsNullOrEmpty(value) && UpdateProper(ref _horizontalSpacingValue, value))
  79. {
  80. HorizontalSpacingChanged?.Invoke(this, EventArgs.Empty);
  81. }
  82. }
  83. }
  84. public event EventHandler FullScreenChanged;
  85. public event EventHandler VerticalSpacingChanged;
  86. public event EventHandler HorizontalSpacingChanged;
  87. public CPDFTileControl()
  88. {
  89. InitializeComponent();
  90. DataContext = this;
  91. }
  92. private void TileChk_Click(object sender, RoutedEventArgs e)
  93. {
  94. var chk = sender as CheckBox;
  95. if (chk != null)
  96. {
  97. if ((bool)chk.IsChecked)
  98. {
  99. IsFullScreen = true;
  100. }
  101. else
  102. {
  103. IsFullScreen = false;
  104. }
  105. }
  106. }
  107. public event PropertyChangedEventHandler PropertyChanged;
  108. protected virtual void OnPropertyChanged(string propertyName = null)
  109. {
  110. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  111. }
  112. protected bool UpdateProper<T>(ref T properValue,
  113. T newValue,
  114. [CallerMemberName] string properName = "")
  115. {
  116. if (object.Equals(properValue, newValue))
  117. return false;
  118. properValue = newValue;
  119. OnPropertyChanged(properName);
  120. return true;
  121. }
  122. }
  123. }