FormFieldCombox.xaml.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using PDF_Office.Model.From;
  2. using System;
  3. using System.Collections.Generic;
  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.Form
  17. {
  18. /// <summary>
  19. /// FormFieldCombox.xaml 的交互逻辑
  20. /// 用于表单显示字段的下拉控件
  21. /// </summary>
  22. public partial class FormFieldCombox : UserControl
  23. {
  24. public FormFieldCombox()
  25. {
  26. InitializeComponent();
  27. InitCombox();
  28. }
  29. public FormFieldType Type
  30. {
  31. get { return (FormFieldType)GetValue(TypeProperty); }
  32. set { SetValue(TypeProperty, value); }
  33. }
  34. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  35. public static readonly DependencyProperty TypeProperty =
  36. DependencyProperty.Register("Type", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible, FormFieldTypePropertyChanged));
  37. private static void FormFieldTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  38. {
  39. var control = d as FormFieldCombox;
  40. var type = (FormFieldType)e.NewValue;
  41. if (control != null)
  42. {
  43. control.Combox.SelectedIndex = (int)type;
  44. }
  45. }
  46. public FormFieldType SetType
  47. {
  48. get { return (FormFieldType)GetValue(SetTypeProperty); }
  49. set { SetValue(SetTypeProperty, value); }
  50. }
  51. // Using a DependencyProperty as the backing store for SetType. This enables animation, styling, binding, etc...
  52. public static readonly DependencyProperty SetTypeProperty =
  53. DependencyProperty.Register("SetType", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible,(d,e)=> {
  54. (d as FormFieldCombox).SetIndexBySetType((FormFieldType)e.NewValue);
  55. }));
  56. /// <summary>
  57. /// 根据settype 设置combox索引
  58. /// </summary>
  59. private void SetIndexBySetType(FormFieldType type)
  60. {
  61. Combox.SelectedIndex=(int)type;
  62. }
  63. private void InitCombox()
  64. {
  65. List<string> list = new List<string>();
  66. list.Add("可见");
  67. list.Add("隐藏");
  68. list.Add("可见但不可打印");
  69. list.Add("隐藏但可打印");
  70. Combox.ItemsSource = list;
  71. }
  72. private void Combox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  73. {
  74. Type = (FormFieldType)Combox.SelectedIndex;
  75. }
  76. }
  77. }