DescriptionDecorator.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Input;
  9. namespace FWindSoft.Wpf.Controls
  10. {
  11. public class DescriptionDecorator: ContentControl
  12. {
  13. public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(object), typeof(DescriptionDecorator), new PropertyMetadata(null, null));
  14. static DescriptionDecorator()
  15. {
  16. DefaultStyleKeyProperty.OverrideMetadata(typeof(DescriptionDecorator), new FrameworkPropertyMetadata(typeof(DescriptionDecorator)));
  17. try
  18. {
  19. HorizontalContentAlignmentProperty.OverrideMetadata(typeof(DescriptionDecorator),
  20. new FrameworkPropertyMetadata(HorizontalAlignment.Stretch, null));
  21. VerticalContentAlignmentProperty.OverrideMetadata(typeof(DescriptionDecorator),
  22. new FrameworkPropertyMetadata(VerticalAlignment.Center, null));
  23. }
  24. catch (Exception ex)
  25. {
  26. }
  27. }
  28. public DescriptionDecorator()
  29. {
  30. //this.HorizontalContentAlignment = HorizontalAlignment.Stretch;
  31. //this.VerticalContentAlignment = VerticalAlignment.Center;
  32. }
  33. public object Description
  34. {
  35. get
  36. {
  37. return base.GetValue(ContentControl.ContentProperty);
  38. }
  39. set
  40. {
  41. base.SetValue(ContentControl.ContentProperty, value);
  42. }
  43. }
  44. }
  45. public class ButtonDecorator : DescriptionDecorator
  46. {
  47. public static readonly DependencyProperty ButtonStyleProperty= DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(ButtonDecorator), new FrameworkPropertyMetadata(null));
  48. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ButtonDecorator), new FrameworkPropertyMetadata(null));
  49. public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(ButtonDecorator), new FrameworkPropertyMetadata(null));
  50. static ButtonDecorator()
  51. {
  52. DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonDecorator), new FrameworkPropertyMetadata(typeof(ButtonDecorator)));
  53. }
  54. public ICommand Command
  55. {
  56. get
  57. {
  58. return (ICommand)base.GetValue(CommandProperty);
  59. }
  60. set
  61. {
  62. base.SetValue(CommandProperty, value);
  63. }
  64. }
  65. public object CommandParameter
  66. {
  67. get
  68. {
  69. return base.GetValue(CommandParameterProperty);
  70. }
  71. set
  72. {
  73. base.SetValue(CommandParameterProperty, value);
  74. }
  75. }
  76. /// <summary>
  77. /// button的样式
  78. /// </summary>
  79. public Style ButtonStyle
  80. {
  81. get
  82. {
  83. return GetValue(ButtonStyleProperty) as Style;
  84. }
  85. set
  86. {
  87. SetValue(ButtonStyleProperty, value);
  88. }
  89. }
  90. }
  91. }