CPDFSearchInputUI.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace compdfkit_tools.PDFControlUI
  16. {
  17. /// <summary>
  18. /// 搜索输入控件
  19. /// </summary>
  20. public partial class CPDFSearchInputUI : UserControl
  21. {
  22. /// <summary>
  23. /// 搜索事件
  24. /// </summary>
  25. public event EventHandler<string> SearchEvent;
  26. /// <summary>
  27. /// 清除搜索输入
  28. /// </summary>
  29. public event EventHandler ClearEvent;
  30. /// <summary>
  31. /// 搜索关键词
  32. /// </summary>
  33. public string SearchKeyWord
  34. {
  35. get
  36. {
  37. return SearchTextBox.Text;
  38. }
  39. set
  40. {
  41. SearchTextBox.Text = value;
  42. }
  43. }
  44. /// <summary>
  45. /// 搜索输入文本框宽度
  46. /// </summary>
  47. public double InputTextBoxWidth
  48. {
  49. get
  50. {
  51. return SearchTextBox.Width;
  52. }
  53. set
  54. {
  55. SearchTextBox.Width = value;
  56. }
  57. }
  58. /// <summary>
  59. /// 搜索输入文本框高度
  60. /// </summary>
  61. public double InputTextBoxHeight
  62. {
  63. get
  64. {
  65. return SearchTextBox.Height;
  66. }
  67. set
  68. {
  69. SearchTextBox.Height = value;
  70. }
  71. }
  72. public CPDFSearchInputUI()
  73. {
  74. InitializeComponent();
  75. }
  76. /// <summary>
  77. /// 输入框回车搜索
  78. /// </summary>
  79. private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
  80. {
  81. if (e.Key == Key.Enter && string.IsNullOrEmpty(SearchKeyWord)==false)
  82. {
  83. SearchEvent?.Invoke(this, SearchKeyWord);
  84. }
  85. }
  86. /// <summary>
  87. /// 清除搜索框
  88. /// </summary>
  89. private void TextClear_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  90. {
  91. SearchKeyWord = string.Empty;
  92. ClearEvent?.Invoke(this,new EventArgs());
  93. }
  94. /// <summary>
  95. /// 搜索按钮点击
  96. /// </summary>
  97. private void SearchBtn_Click(object sender, RoutedEventArgs e)
  98. {
  99. if (string.IsNullOrEmpty(SearchKeyWord) == false)
  100. {
  101. SearchEvent?.Invoke(this, SearchKeyWord);
  102. }
  103. }
  104. }
  105. }