WritableComboBox.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using ImTools;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace PDF_Office.CustomControl
  19. {
  20. /// <summary>
  21. /// WritableComboBox.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class WritableComboBox : UserControl
  24. {
  25. public bool IsCurrentPage
  26. {
  27. get { return (bool)GetValue(IsCurrentPageProperty); }
  28. set { SetValue(IsCurrentPageProperty, value); }
  29. }
  30. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  31. public static readonly DependencyProperty IsCurrentPageProperty =
  32. DependencyProperty.Register("IsCurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false));
  33. public bool CurrentPage
  34. {
  35. get { return (bool)GetValue(CurrentPageProperty); }
  36. set { SetValue(CurrentPageProperty, value); }
  37. }
  38. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  39. public static readonly DependencyProperty CurrentPageProperty =
  40. DependencyProperty.Register("CurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false));
  41. public string SelectedIndex
  42. {
  43. get { return (string)GetValue(SelectedIndexProperty); }
  44. set { SetValue(SelectedIndexProperty, value); }
  45. }
  46. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  47. public static readonly DependencyProperty SelectedIndexProperty =
  48. DependencyProperty.Register("SelectedIndex", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  49. public string Text
  50. {
  51. get { return (string)GetValue(TextProperty); }
  52. set { SetValue(TextProperty, value); }
  53. }
  54. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  55. public static readonly DependencyProperty TextProperty =
  56. DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  57. /// <summary>
  58. /// 把子控件的事件传递出去,方便绑定
  59. /// </summary>
  60. public event RoutedEventHandler SelectionChanged;
  61. /// <summary>
  62. /// 把子控件的事件传递出去,方便绑定
  63. /// </summary>
  64. public event RoutedEventHandler TextChanged;
  65. public WritableComboBox()
  66. {
  67. InitializeComponent();
  68. }
  69. private void writableComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  70. {
  71. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  72. {
  73. this.writableTextBox.Width = this.writableComboBox.ActualWidth - 18;
  74. Trace.WriteLine(this.writableComboBox.ActualWidth);
  75. this.writableTextBox.Visibility = Visibility.Visible;
  76. }
  77. else
  78. {
  79. if (this.writableTextBox != null)
  80. {
  81. this.writableTextBox.Visibility = Visibility.Hidden;
  82. }
  83. }
  84. if (this.writableComboBox.Items.Count == 5)
  85. {
  86. if (this.writableComboBox.SelectedIndex == 1)
  87. { IsCurrentPage = true; }
  88. else
  89. {
  90. IsCurrentPage = false;
  91. }
  92. }
  93. this.SelectedIndex = this.writableComboBox.SelectedIndex.ToString();
  94. SelectionChanged?.Invoke(sender,e);
  95. }
  96. private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
  97. {
  98. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  99. {
  100. Text = this.writableTextBox.Text;
  101. }
  102. else { Text = ""; }
  103. TextChanged?.Invoke(sender,e);
  104. }
  105. }
  106. }