WritableComboBox.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 WritableComboBox()
  26. {
  27. InitializeComponent();
  28. }
  29. private void writableComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  30. {
  31. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  32. {
  33. this.writableTextBox.Width = this.writableComboBox.ActualWidth - 18;
  34. Trace.WriteLine(this.writableComboBox.ActualWidth);
  35. this.writableTextBox.Visibility = Visibility.Visible;
  36. }
  37. else
  38. {
  39. if (this.writableTextBox != null)
  40. {
  41. this.writableTextBox.Visibility = Visibility.Hidden;
  42. }
  43. }
  44. if (this.writableComboBox.Items.Count == 5)
  45. {
  46. if (this.writableComboBox.SelectedIndex == 1)
  47. { IsCurrentPage = true; }
  48. else
  49. {
  50. IsCurrentPage = false;
  51. }
  52. }
  53. this.SelectedIndex = this.writableComboBox.SelectedIndex.ToString();
  54. }
  55. public bool IsCurrentPage
  56. {
  57. get { return (bool)GetValue(IsCurrentPageProperty); }
  58. set { SetValue(IsCurrentPageProperty, value); }
  59. }
  60. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  61. public static readonly DependencyProperty IsCurrentPageProperty =
  62. DependencyProperty.Register("IsCurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false));
  63. public bool CurrentPage
  64. {
  65. get { return (bool)GetValue(CurrentPageProperty); }
  66. set { SetValue(CurrentPageProperty, value); }
  67. }
  68. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  69. public static readonly DependencyProperty CurrentPageProperty =
  70. DependencyProperty.Register("CurrentPage", typeof(bool), typeof(WritableComboBox), new PropertyMetadata(false));
  71. public string SelectedIndex
  72. {
  73. get { return (string)GetValue(SelectedIndexProperty); }
  74. set { SetValue(SelectedIndexProperty, value); }
  75. }
  76. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  77. public static readonly DependencyProperty SelectedIndexProperty =
  78. DependencyProperty.Register("SelectedIndex", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  79. public string Text
  80. {
  81. get { return (string)GetValue(TextProperty); }
  82. set { SetValue(TextProperty, value); }
  83. }
  84. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  85. public static readonly DependencyProperty TextProperty =
  86. DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  87. private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
  88. {
  89. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  90. {
  91. Text = this.writableTextBox.Text;
  92. }
  93. else { Text = ""; }
  94. }
  95. }
  96. }