PathButton.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace PDF_Master.CustomControl
  16. {
  17. public class PathButton : Button
  18. {
  19. static PathButton()
  20. {
  21. DefaultStyleKeyProperty.OverrideMetadata(typeof(PathButton), new FrameworkPropertyMetadata(typeof(PathButton)));
  22. }
  23. public override void OnApplyTemplate()
  24. {
  25. base.OnApplyTemplate();
  26. if (this.MouseOverBackground == null)
  27. {
  28. this.MouseOverBackground = Background;
  29. }
  30. if (this.MouseDownBackground == null)
  31. {
  32. if (this.MouseOverBackground == null)
  33. {
  34. this.MouseDownBackground = Background;
  35. }
  36. else
  37. {
  38. this.MouseDownBackground = MouseOverBackground;
  39. }
  40. }
  41. if (this.MouseOverBorderBrush == null)
  42. {
  43. this.MouseOverBorderBrush = BorderBrush;
  44. }
  45. if (this.MouseDownBorderBrush == null)
  46. {
  47. if (this.MouseOverBorderBrush == null)
  48. {
  49. this.MouseDownBorderBrush = BorderBrush;
  50. }
  51. else
  52. {
  53. this.MouseDownBorderBrush = MouseOverBorderBrush;
  54. }
  55. }
  56. if (this.MouseOverForeground == null)
  57. {
  58. this.MouseOverForeground = Foreground;
  59. }
  60. if (this.MouseDownForeground == null)
  61. {
  62. if (this.MouseOverForeground == null)
  63. {
  64. this.MouseDownForeground = Foreground;
  65. }
  66. else
  67. {
  68. this.MouseDownForeground = this.MouseOverForeground;
  69. }
  70. }
  71. if (this.IconChecked == null)
  72. {
  73. if (this.IconPress == null)
  74. {
  75. this.IconChecked = Icon;
  76. }
  77. else
  78. {
  79. this.IconChecked = this.IconPress;
  80. }
  81. }
  82. if (this.IconCheckedFill == null)
  83. {
  84. if (this.IconPressFill == null)
  85. {
  86. this.IconCheckedFill = IconFill;
  87. }
  88. else
  89. {
  90. this.IconCheckedFill = this.IconPressFill;
  91. }
  92. }
  93. }
  94. #region 依赖项属性
  95. /// <summary>
  96. /// 鼠标移上去的背景颜色
  97. /// </summary>
  98. public static readonly DependencyProperty MouseOverBackgroundProperty
  99. = DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(PathButton));
  100. /// <summary>
  101. /// 鼠标按下去的背景颜色
  102. /// </summary>
  103. public static readonly DependencyProperty MouseDownBackgroundProperty
  104. = DependencyProperty.Register("MouseDownBackground", typeof(Brush), typeof(PathButton));
  105. /// <summary>
  106. /// 鼠标移上去的字体颜色
  107. /// </summary>
  108. public static readonly DependencyProperty MouseOverForegroundProperty
  109. = DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(PathButton), new PropertyMetadata(null, null));
  110. /// <summary>
  111. /// 鼠标按下去的字体颜色
  112. /// </summary>
  113. public static readonly DependencyProperty MouseDownForegroundProperty
  114. = DependencyProperty.Register("MouseDownForeground", typeof(Brush), typeof(PathButton), new PropertyMetadata(null, null));
  115. /// <summary>
  116. /// 鼠标移上去的边框颜色
  117. /// </summary>
  118. public static readonly DependencyProperty MouseOverBorderBrushProperty
  119. = DependencyProperty.Register("MouseOverBorderBrush", typeof(Brush), typeof(PathButton), new PropertyMetadata(null, null));
  120. /// <summary>
  121. /// 鼠标按下去的边框颜色
  122. /// </summary>
  123. public static readonly DependencyProperty MouseDownBorderBrushProperty
  124. = DependencyProperty.Register("MouseDownBorderBrush", typeof(Brush), typeof(PathButton), new PropertyMetadata(null, null));
  125. /// <summary>
  126. /// 圆角
  127. /// </summary>
  128. public static readonly DependencyProperty CornerRadiusProperty
  129. = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(PathButton), null);
  130. //图标
  131. public static readonly DependencyProperty IconProperty
  132. = DependencyProperty.Register("Icon", typeof(Geometry), typeof(PathButton), null);
  133. //图标填充色
  134. public static readonly DependencyProperty IconFillProperty
  135. = DependencyProperty.Register("IconFill", typeof(Brush), typeof(PathButton), null);
  136. //图标透明度
  137. public static readonly DependencyProperty IconOpacityProperty
  138. = DependencyProperty.Register("IconOpacity", typeof(double), typeof(PathButton), null);
  139. //按钮是否被选中
  140. public static readonly DependencyProperty IsCheckedProperty
  141. = DependencyProperty.Register("IsChecked", typeof(bool), typeof(PathButton), null);
  142. //选中的图标
  143. public static readonly DependencyProperty IconCheckedProperty
  144. = DependencyProperty.Register("IconChecked", typeof(Geometry), typeof(PathButton), null);
  145. //选中的图标填充色
  146. public static readonly DependencyProperty IconCheckedFillProperty
  147. = DependencyProperty.Register("IconCheckedFill", typeof(Brush), typeof(PathButton), null);
  148. //选中的图标的透明度
  149. public static readonly DependencyProperty IconCheckedOpacityProperty
  150. = DependencyProperty.Register("IconCheckedOpacity", typeof(double), typeof(PathButton), null);
  151. //鼠标移上去的图标
  152. public static readonly DependencyProperty IconMouseOverProperty
  153. = DependencyProperty.Register("IconMouseOver", typeof(Geometry), typeof(PathButton), null);
  154. //鼠标移上去的图标填充色
  155. public static readonly DependencyProperty IconMouseOverFillProperty
  156. = DependencyProperty.Register("IconMouseOverFill", typeof(Brush), typeof(PathButton), null);
  157. //鼠标移上去的透明度
  158. public static readonly DependencyProperty IconMouseOverOpacityProperty
  159. = DependencyProperty.Register("IconMouseOverOpacity", typeof(double), typeof(PathButton), null);
  160. //鼠标按下去的图标
  161. public static readonly DependencyProperty IconPressProperty
  162. = DependencyProperty.Register("IconPress", typeof(Geometry), typeof(PathButton), null);
  163. //鼠标按下去的图标填充色
  164. public static readonly DependencyProperty IconPressFillProperty
  165. = DependencyProperty.Register("IconPressFill", typeof(Brush), typeof(PathButton), null);
  166. //鼠标按下去的透明度
  167. public static readonly DependencyProperty IconPressOpacityProperty
  168. = DependencyProperty.Register("IconPressOpacity", typeof(double), typeof(PathButton), null);
  169. //图标高度
  170. public static readonly DependencyProperty IconHeightProperty
  171. = DependencyProperty.Register("IconHeight", typeof(double), typeof(PathButton), new PropertyMetadata(24.0, null));
  172. //图标宽度
  173. public static readonly DependencyProperty IconWidthProperty
  174. = DependencyProperty.Register("IconWidth", typeof(double), typeof(PathButton), new PropertyMetadata(24.0, null));
  175. //图标和内容的对齐方式
  176. public static readonly DependencyProperty IconContentOrientationProperty
  177. = DependencyProperty.Register("IconContentOrientation", typeof(Orientation), typeof(PathButton), new PropertyMetadata(Orientation.Horizontal, null));
  178. //图标和内容的距离
  179. public static readonly DependencyProperty IconContentMarginProperty
  180. = DependencyProperty.Register("IconContentMargin", typeof(Thickness), typeof(PathButton), new PropertyMetadata(new Thickness(0, 0, 0, 0), null));
  181. #endregion
  182. #region 属性包装
  183. public Brush MouseOverBackground
  184. {
  185. get
  186. {
  187. return (Brush)GetValue(MouseOverBackgroundProperty);
  188. }
  189. set { SetValue(MouseOverBackgroundProperty, value); }
  190. }
  191. public Brush MouseDownBackground
  192. {
  193. get
  194. {
  195. return (Brush)GetValue(MouseDownBackgroundProperty);
  196. }
  197. set { SetValue(MouseDownBackgroundProperty, value); }
  198. }
  199. public Brush MouseOverForeground
  200. {
  201. get
  202. {
  203. return (Brush)GetValue(MouseOverForegroundProperty);
  204. }
  205. set { SetValue(MouseOverForegroundProperty, value); }
  206. }
  207. public Brush MouseDownForeground
  208. {
  209. get
  210. {
  211. return (Brush)GetValue(MouseDownForegroundProperty);
  212. }
  213. set { SetValue(MouseDownForegroundProperty, value); }
  214. }
  215. public Brush MouseOverBorderBrush
  216. {
  217. get { return (Brush)GetValue(MouseOverBorderBrushProperty); }
  218. set { SetValue(MouseOverBorderBrushProperty, value); }
  219. }
  220. public Brush MouseDownBorderBrush
  221. {
  222. get { return (Brush)GetValue(MouseDownBorderBrushProperty); }
  223. set { SetValue(MouseDownBorderBrushProperty, value); }
  224. }
  225. public CornerRadius CornerRadius
  226. {
  227. get { return (CornerRadius)GetValue(CornerRadiusProperty); }
  228. set { SetValue(CornerRadiusProperty, value); }
  229. }
  230. public Geometry Icon
  231. {
  232. get { return (Geometry)GetValue(IconProperty); }
  233. set { SetValue(IconProperty, value); }
  234. }
  235. public Brush IconFill
  236. {
  237. get { return (Brush)GetValue(IconFillProperty); }
  238. set { SetValue(IconFillProperty, value); }
  239. }
  240. public double IconOpacity
  241. {
  242. get { return (double)GetValue(IconOpacityProperty); }
  243. set { SetValue(IconOpacityProperty, value); }
  244. }
  245. public bool IsChecked
  246. {
  247. get { return (bool)GetValue(IsCheckedProperty); }
  248. set { SetValue(IsCheckedProperty, value); }
  249. }
  250. public Geometry IconChecked
  251. {
  252. get { return (Geometry)GetValue(IconCheckedProperty); }
  253. set { SetValue(IconCheckedProperty, value); }
  254. }
  255. public Brush IconCheckedFill
  256. {
  257. get { return (Brush)GetValue(IconCheckedFillProperty); }
  258. set { SetValue(IconCheckedFillProperty, value); }
  259. }
  260. public double IconCheckedOpacity
  261. {
  262. get { return (double)GetValue(IconCheckedOpacityProperty); }
  263. set { SetValue(IconCheckedOpacityProperty, value); }
  264. }
  265. public Geometry IconMouseOver
  266. {
  267. get { return (Geometry)GetValue(IconMouseOverProperty); }
  268. set { SetValue(IconMouseOverProperty, value); }
  269. }
  270. public Brush IconMouseOverFill
  271. {
  272. get { return (Brush)GetValue(IconMouseOverProperty); }
  273. set { SetValue(IconMouseOverProperty, value); }
  274. }
  275. public double IconMouseOverOpacity
  276. {
  277. get { return (double)GetValue(IconMouseOverProperty); }
  278. set { SetValue(IconMouseOverProperty, value); }
  279. }
  280. public Geometry IconPress
  281. {
  282. get { return (Geometry)GetValue(IconPressProperty); }
  283. set { SetValue(IconPressProperty, value); }
  284. }
  285. public Brush IconPressFill
  286. {
  287. get { return (Brush)GetValue(IconPressFillProperty); }
  288. set { SetValue(IconPressFillProperty, value); }
  289. }
  290. public double IconPressOpacity
  291. {
  292. get { return (double)GetValue(IconPressOpacityProperty); }
  293. set { SetValue(IconPressOpacityProperty, value); }
  294. }
  295. public double IconHeight
  296. {
  297. get { return (double)GetValue(IconHeightProperty); }
  298. set { SetValue(IconHeightProperty, value); }
  299. }
  300. public double IconWidth
  301. {
  302. get { return (double)GetValue(IconWidthProperty); }
  303. set { SetValue(IconWidthProperty, value); }
  304. }
  305. public Orientation IconContentOrientation
  306. {
  307. get { return (Orientation)GetValue(IconContentOrientationProperty); }
  308. set { SetValue(IconContentOrientationProperty, value); }
  309. }
  310. public Thickness IconContentMargin
  311. {
  312. get { return (Thickness)GetValue(IconContentMarginProperty); }
  313. set { SetValue(IconContentMarginProperty, value); }
  314. }
  315. #endregion
  316. }
  317. }