PropertyItem.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using HandyControl.Data;
  6. namespace HandyControl.Controls;
  7. public class PropertyItem : ListBoxItem
  8. {
  9. public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
  10. nameof(Value), typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
  11. public object Value
  12. {
  13. get => GetValue(ValueProperty);
  14. set => SetValue(ValueProperty, value);
  15. }
  16. public static readonly DependencyProperty DisplayNameProperty = DependencyProperty.Register(
  17. nameof(DisplayName), typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
  18. public string DisplayName
  19. {
  20. get => (string) GetValue(DisplayNameProperty);
  21. set => SetValue(DisplayNameProperty, value);
  22. }
  23. public static readonly DependencyProperty PropertyNameProperty = DependencyProperty.Register(
  24. nameof(PropertyName), typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
  25. public string PropertyName
  26. {
  27. get => (string) GetValue(PropertyNameProperty);
  28. set => SetValue(PropertyNameProperty, value);
  29. }
  30. public static readonly DependencyProperty PropertyTypeProperty = DependencyProperty.Register(
  31. nameof(PropertyType), typeof(Type), typeof(PropertyItem), new PropertyMetadata(default(Type)));
  32. public Type PropertyType
  33. {
  34. get => (Type) GetValue(PropertyTypeProperty);
  35. set => SetValue(PropertyTypeProperty, value);
  36. }
  37. public static readonly DependencyProperty PropertyTypeNameProperty = DependencyProperty.Register(
  38. nameof(PropertyTypeName), typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
  39. public string PropertyTypeName
  40. {
  41. get => (string) GetValue(PropertyTypeNameProperty);
  42. set => SetValue(PropertyTypeNameProperty, value);
  43. }
  44. public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
  45. nameof(Description), typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
  46. public string Description
  47. {
  48. get => (string) GetValue(DescriptionProperty);
  49. set => SetValue(DescriptionProperty, value);
  50. }
  51. public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(
  52. nameof(IsReadOnly), typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
  53. public bool IsReadOnly
  54. {
  55. get => (bool) GetValue(IsReadOnlyProperty);
  56. set => SetValue(IsReadOnlyProperty, ValueBoxes.BooleanBox(value));
  57. }
  58. public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register(
  59. nameof(DefaultValue), typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
  60. public object DefaultValue
  61. {
  62. get => GetValue(DefaultValueProperty);
  63. set => SetValue(DefaultValueProperty, value);
  64. }
  65. public static readonly DependencyProperty CategoryProperty = DependencyProperty.Register(
  66. nameof(Category), typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
  67. public string Category
  68. {
  69. get => (string) GetValue(CategoryProperty);
  70. set => SetValue(CategoryProperty, value);
  71. }
  72. public static readonly DependencyProperty EditorProperty = DependencyProperty.Register(
  73. nameof(Editor), typeof(PropertyEditorBase), typeof(PropertyItem), new PropertyMetadata(default(PropertyEditorBase)));
  74. public PropertyEditorBase Editor
  75. {
  76. get => (PropertyEditorBase) GetValue(EditorProperty);
  77. set => SetValue(EditorProperty, value);
  78. }
  79. public static readonly DependencyProperty EditorElementProperty = DependencyProperty.Register(
  80. nameof(EditorElement), typeof(FrameworkElement), typeof(PropertyItem), new PropertyMetadata(default(FrameworkElement)));
  81. public FrameworkElement EditorElement
  82. {
  83. get => (FrameworkElement) GetValue(EditorElementProperty);
  84. set => SetValue(EditorElementProperty, value);
  85. }
  86. public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register(
  87. nameof(IsExpandedEnabled), typeof(bool), typeof(PropertyItem), new PropertyMetadata(ValueBoxes.FalseBox));
  88. public bool IsExpandedEnabled
  89. {
  90. get => (bool) GetValue(IsExpandedEnabledProperty);
  91. set => SetValue(IsExpandedEnabledProperty, ValueBoxes.BooleanBox(value));
  92. }
  93. public PropertyDescriptor PropertyDescriptor { get; set; }
  94. public virtual void InitElement()
  95. {
  96. if (Editor == null) return;
  97. EditorElement = Editor.CreateElement(this);
  98. Editor.CreateBinding(this, EditorElement);
  99. }
  100. }