星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Media;
  4. namespace ComeCapture.Controls
  5. {
  6. [TemplatePart(Name = "PART_TextBox", Type = typeof(TextBox))]
  7. public class TextBoxControl : Control
  8. {
  9. public TextBox _TextBox;
  10. static TextBoxControl()
  11. {
  12. DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxControl), new FrameworkPropertyMetadata(typeof(TextBoxControl)));
  13. }
  14. public TextBoxControl()
  15. {
  16. AddHandler(GotFocusEvent, new RoutedEventHandler((sender, e) =>
  17. {
  18. MyFocus = true;
  19. }));
  20. AddHandler(LostFocusEvent, new RoutedEventHandler((sender, e) =>
  21. {
  22. MyFocus = false;
  23. }));
  24. }
  25. public override void OnApplyTemplate()
  26. {
  27. base.OnApplyTemplate();
  28. _TextBox = GetTemplateChild("PART_TextBox") as TextBox;
  29. _TextBox.MaxWidth = JieTuWindow.Current.MainImage.Width - JieTuWindow.Current.MainImage.point.X - 3;
  30. _TextBox.MaxHeight = JieTuWindow.Current.MainImage.Height - JieTuWindow.Current.MainImage.point.Y - 3;
  31. }
  32. #region BorderColor DependencyProperty
  33. public Color BorderColor
  34. {
  35. get => (Color)GetValue(BorderColorProperty);
  36. set => SetValue(BorderColorProperty, value);
  37. }
  38. public static readonly DependencyProperty BorderColorProperty =
  39. DependencyProperty.Register("BorderColor", typeof(Color), typeof(TextBoxControl),
  40. new PropertyMetadata(Colors.Transparent, new PropertyChangedCallback(TextBoxControl.OnBorderColorPropertyChanged)));
  41. private static void OnBorderColorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  42. {
  43. if (obj is TextBoxControl)
  44. {
  45. (obj as TextBoxControl).OnBorderColorValueChanged();
  46. }
  47. }
  48. protected void OnBorderColorValueChanged()
  49. {
  50. }
  51. #endregion BorderColor DependencyProperty
  52. #region MyFocus DependencyProperty
  53. public bool MyFocus
  54. {
  55. get => (bool)GetValue(MyFocusProperty);
  56. set => SetValue(MyFocusProperty, value);
  57. }
  58. public static readonly DependencyProperty MyFocusProperty =
  59. DependencyProperty.Register("MyFocus", typeof(bool), typeof(TextBoxControl),
  60. new PropertyMetadata(true, new PropertyChangedCallback(TextBoxControl.OnMyFocusPropertyChanged)));
  61. private static void OnMyFocusPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  62. {
  63. if (obj is TextBoxControl)
  64. {
  65. (obj as TextBoxControl).OnMyFocusValueChanged();
  66. }
  67. }
  68. protected void OnMyFocusValueChanged()
  69. {
  70. if (!MyFocus)
  71. {
  72. if (string.IsNullOrEmpty(_TextBox.Text))
  73. {
  74. JieTuWindow.RemoveControl(this);
  75. }
  76. else
  77. {
  78. JieTuWindow.Current.MainImage.ResetLimit(Canvas.GetLeft(this), Canvas.GetTop(this), (Canvas.GetLeft(this) + ActualWidth), (Canvas.GetTop(this) + ActualHeight));
  79. JieTuWindow.Register(this);
  80. }
  81. JieTuWindow.Current.MainImage._Text = null;
  82. }
  83. }
  84. #endregion MyFocus DependencyProperty
  85. }
  86. }