PathRadioButton.cs 13 KB

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