ImageButton.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Windows;
  2. using System.Windows.Controls.Primitives;
  3. using System.Windows.Media;
  4. namespace Muchinfo.WPF.Controls.Button
  5. {
  6. /// <summary>
  7. /// Class ImageButton.
  8. /// </summary>
  9. public class ImageButton : ToggleButton
  10. {
  11. static ImageButton()
  12. {
  13. DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
  14. }
  15. #region New Dependency Properties
  16. public ImageSource NormalImageSource
  17. {
  18. get { return (ImageSource)GetValue(NormalImageSourceProperty); }
  19. set { SetValue(NormalImageSourceProperty, value); }
  20. }
  21. public static readonly DependencyProperty NormalImageSourceProperty =
  22. DependencyProperty.Register("NormalImageSource", typeof(ImageSource), typeof(ImageButton),
  23. new PropertyMetadata(null));
  24. public ImageSource HoverImageSource
  25. {
  26. get { return (ImageSource)GetValue(HoverImageSourceProperty); }
  27. set { SetValue(HoverImageSourceProperty, value); }
  28. }
  29. public static readonly DependencyProperty HoverImageSourceProperty =
  30. DependencyProperty.Register("HoverImageSource", typeof(ImageSource), typeof(ImageButton),
  31. new PropertyMetadata(null));
  32. public ImageSource PressedImageSource
  33. {
  34. get { return (ImageSource)GetValue(PressedImageSourceProperty); }
  35. set { SetValue(PressedImageSourceProperty, value); }
  36. }
  37. public static readonly DependencyProperty PressedImageSourceProperty =
  38. DependencyProperty.Register("PressedImageSource", typeof(ImageSource), typeof(ImageButton),
  39. new PropertyMetadata(null));
  40. public ImageSource DisabledImageSource
  41. {
  42. get { return (ImageSource)GetValue(DisabledImageSourceProperty); }
  43. set { SetValue(DisabledImageSourceProperty, value); }
  44. }
  45. public static readonly DependencyProperty DisabledImageSourceProperty =
  46. DependencyProperty.Register("DisabledImageSource", typeof(ImageSource), typeof(ImageButton),
  47. new PropertyMetadata(null));
  48. public Visibility BorderVisibility
  49. {
  50. get { return (Visibility)GetValue(BorderVisibilityProperty); }
  51. set { SetValue(BorderVisibilityProperty, value); }
  52. }
  53. public static readonly DependencyProperty BorderVisibilityProperty =
  54. DependencyProperty.Register("BorderVisibility", typeof(Visibility), typeof(ImageButton),
  55. new FrameworkPropertyMetadata(Visibility.Collapsed, FrameworkPropertyMetadataOptions.AffectsRender));
  56. public double ImageWidth
  57. {
  58. get { return (double)GetValue(ImageWidthProperty); }
  59. set { SetValue(ImageWidthProperty, value); }
  60. }
  61. public static readonly DependencyProperty ImageWidthProperty =
  62. DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton),
  63. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  64. public double ImageHeight
  65. {
  66. get { return (double)GetValue(ImageHeightProperty); }
  67. set { SetValue(ImageHeightProperty, value); }
  68. }
  69. public static readonly DependencyProperty ImageHeightProperty =
  70. DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton),
  71. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  72. public CornerRadius BorderCornerRadius
  73. {
  74. get { return (CornerRadius)GetValue(BorderCornerRadiusProperty); }
  75. set { SetValue(BorderCornerRadiusProperty, value); }
  76. }
  77. public static readonly DependencyProperty BorderCornerRadiusProperty =
  78. DependencyProperty.Register("BorderCornerRadius", typeof(CornerRadius), typeof(ImageButton),
  79. new PropertyMetadata(new CornerRadius(2), null));
  80. public Stretch ImageStretch
  81. {
  82. get { return (Stretch)GetValue(ImageStretchProperty); }
  83. set { SetValue(ImageStretchProperty, value); }
  84. }
  85. public static readonly DependencyProperty ImageStretchProperty =
  86. DependencyProperty.Register("ImageStretch", typeof(Stretch), typeof(ImageButton),
  87. new PropertyMetadata(Stretch.None, null));
  88. #endregion
  89. }
  90. }