WritableComboBox.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace PDF_Office.CustomControl
  17. {
  18. /// <summary>
  19. /// WritableComboBox.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class WritableComboBox : UserControl
  22. {
  23. public WritableComboBox()
  24. {
  25. InitializeComponent();
  26. }
  27. private void writableComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  28. {
  29. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  30. {
  31. this.writableTextBox.Width = this.writableComboBox.ActualWidth - 18;
  32. Trace.WriteLine(this.writableComboBox.ActualWidth);
  33. this.writableTextBox.Visibility = Visibility.Visible;
  34. }
  35. else
  36. {
  37. if (this.writableTextBox != null) {
  38. this.writableTextBox.Visibility = Visibility.Hidden;
  39. }
  40. this.SelectedIndex=this.writableComboBox.SelectedIndex.ToString();
  41. }
  42. }
  43. public string SelectedIndex
  44. {
  45. get { return (string)GetValue(SelectedIndexProperty); }
  46. set { SetValue(SelectedIndexProperty, value); }
  47. }
  48. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  49. public static readonly DependencyProperty SelectedIndexProperty =
  50. DependencyProperty.Register("SelectedIndex", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  51. public string Text
  52. {
  53. get { return (string)GetValue(TextProperty); }
  54. set { SetValue(TextProperty, value); }
  55. }
  56. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  57. public static readonly DependencyProperty TextProperty =
  58. DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
  59. private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
  60. {
  61. if (this.writableComboBox.SelectedIndex == this.writableComboBox.Items.Count - 1)
  62. {
  63. Text = this.writableTextBox.Text;
  64. }
  65. else { Text = ""; }
  66. }
  67. }
  68. }