FormFieldCombox.xaml.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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("MyProperty", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible));
  37. public FormFieldType SetType
  38. {
  39. get { return (FormFieldType)GetValue(SetTypeProperty); }
  40. set { SetValue(SetTypeProperty, value); }
  41. }
  42. // Using a DependencyProperty as the backing store for SetType. This enables animation, styling, binding, etc...
  43. public static readonly DependencyProperty SetTypeProperty =
  44. DependencyProperty.Register("SetType", typeof(FormFieldType), typeof(FormFieldCombox), new PropertyMetadata(FormFieldType.visible,(d,e)=> {
  45. (d as FormFieldCombox).SetIndexBySetType((FormFieldType)e.NewValue);
  46. }));
  47. /// <summary>
  48. /// 根据settype 设置combox索引
  49. /// </summary>
  50. private void SetIndexBySetType(FormFieldType type)
  51. {
  52. Combox.SelectedIndex=(int)type;
  53. }
  54. private void InitCombox()
  55. {
  56. List<string> list = new List<string>();
  57. list.Add("可见");
  58. list.Add("隐藏");
  59. list.Add("可见但不可打印");
  60. list.Add("隐藏但可打印");
  61. Combox.ItemsSource = list;
  62. }
  63. private void Combox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. Type = (FormFieldType)Combox.SelectedIndex;
  66. }
  67. }
  68. }