PathRadioButton.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 MouseOverBackgroundOpacityProperty
  103. = DependencyProperty.Register("MouseOverBackgroundOpacity", typeof(double), typeof(PathRadioButton), new PropertyMetadata(1.0, null));
  104. /// <summary>
  105. /// 鼠标按下去的背景颜色透明度
  106. /// </summary>
  107. public static readonly DependencyProperty MouseDownBackgroundOpacityProperty
  108. = DependencyProperty.Register("MouseDownBackgroundOpacity", typeof(double), typeof(PathRadioButton), new PropertyMetadata(1.0, null));
  109. /// <summary>
  110. /// 鼠标移上去的字体颜色
  111. /// </summary>
  112. public static readonly DependencyProperty MouseOverForegroundProperty
  113. = DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(PathRadioButton), new PropertyMetadata(null, null));
  114. /// <summary>
  115. /// 鼠标按下去的字体颜色
  116. /// </summary>
  117. public static readonly DependencyProperty MouseDownForegroundProperty
  118. = DependencyProperty.Register("MouseDownForeground", typeof(Brush), typeof(PathRadioButton), new PropertyMetadata(null, null));
  119. /// <summary>
  120. /// 鼠标移上去的边框颜色
  121. /// </summary>
  122. public static readonly DependencyProperty MouseOverBorderBrushProperty
  123. = DependencyProperty.Register("MouseOverBorderBrush", typeof(Brush), typeof(PathRadioButton), new PropertyMetadata(null, null));
  124. /// <summary>
  125. /// 鼠标按下去的边框颜色
  126. /// </summary>
  127. public static readonly DependencyProperty MouseDownBorderBrushProperty
  128. = DependencyProperty.Register("MouseDownBorderBrush", typeof(Brush), typeof(PathRadioButton), new PropertyMetadata(null, null));
  129. /// <summary>
  130. /// 圆角
  131. /// </summary>
  132. public static readonly DependencyProperty CornerRadiusProperty
  133. = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(PathRadioButton), null);
  134. //图标
  135. public static readonly DependencyProperty IconProperty
  136. = DependencyProperty.Register("Icon", typeof(Geometry), typeof(PathRadioButton), null);
  137. //图标填充色
  138. public static readonly DependencyProperty IconFillProperty
  139. = DependencyProperty.Register("IconFill", typeof(Brush), typeof(PathRadioButton), null);
  140. //图标透明度
  141. public static readonly DependencyProperty IconOpacityProperty
  142. = DependencyProperty.Register("IconOpacity", typeof(double), typeof(PathRadioButton), null);
  143. //选中的图标
  144. public static readonly DependencyProperty IconCheckedProperty
  145. = DependencyProperty.Register("IconChecked", typeof(Geometry), typeof(PathRadioButton), null);
  146. //选中的图标填充色
  147. public static readonly DependencyProperty IconCheckedFillProperty
  148. = DependencyProperty.Register("IconCheckedFill", typeof(Brush), typeof(PathRadioButton), null);
  149. //选中的图标的透明度
  150. public static readonly DependencyProperty IconCheckedOpacityProperty
  151. = DependencyProperty.Register("IconCheckedOpacity", typeof(double), typeof(PathRadioButton), null);
  152. //鼠标移上去的图标
  153. public static readonly DependencyProperty IconMouseOverProperty
  154. = DependencyProperty.Register("IconMouseOver", typeof(Geometry), typeof(PathRadioButton), null);
  155. //鼠标移上去的图标填充色
  156. public static readonly DependencyProperty IconMouseOverFillProperty
  157. = DependencyProperty.Register("IconMouseOverFill", typeof(Brush), typeof(PathRadioButton), null);
  158. //鼠标移上去的透明度
  159. public static readonly DependencyProperty IconMouseOverOpacityProperty
  160. = DependencyProperty.Register("IconMouseOverOpacity", typeof(double), typeof(PathRadioButton), null);
  161. //鼠标按下去的图标
  162. public static readonly DependencyProperty IconPressProperty
  163. = DependencyProperty.Register("IconPress", typeof(Geometry), typeof(PathRadioButton), null);
  164. //鼠标按下去的图标填充色
  165. public static readonly DependencyProperty IconPressFillProperty
  166. = DependencyProperty.Register("IconPressFill", typeof(Brush), typeof(PathRadioButton), null);
  167. //鼠标按下去的透明度
  168. public static readonly DependencyProperty IconPressOpacityProperty
  169. = DependencyProperty.Register("IconPressOpacity", typeof(double), typeof(PathRadioButton), null);
  170. //图标高度
  171. public static readonly DependencyProperty IconHeightProperty
  172. = DependencyProperty.Register("IconHeight", typeof(double), typeof(PathRadioButton), new PropertyMetadata(24.0, null));
  173. //图标宽度
  174. public static readonly DependencyProperty IconWidthProperty
  175. = DependencyProperty.Register("IconWidth", typeof(double), typeof(PathRadioButton), new PropertyMetadata(24.0, null));
  176. //图标和内容的对齐方式
  177. public static readonly DependencyProperty IconContentOrientationProperty
  178. = DependencyProperty.Register("IconContentOrientation", typeof(Orientation), typeof(PathRadioButton), new PropertyMetadata(Orientation.Horizontal, null));
  179. //图标和内容的距离
  180. public static readonly DependencyProperty IconContentMarginProperty
  181. = DependencyProperty.Register("IconContentMargin", typeof(Thickness), typeof(PathRadioButton), new PropertyMetadata(new Thickness(0, 0, 0, 0), null));
  182. #endregion
  183. #region 属性包装
  184. public Brush MouseOverBackground
  185. {
  186. get
  187. {
  188. return (Brush)GetValue(MouseOverBackgroundProperty);
  189. }
  190. set { SetValue(MouseOverBackgroundProperty, value); }
  191. }
  192. public Brush MouseDownBackground
  193. {
  194. get
  195. {
  196. return (Brush)GetValue(MouseDownBackgroundProperty);
  197. }
  198. set { SetValue(MouseDownBackgroundProperty, value); }
  199. }
  200. public double MouseOverBackgroundOpacity
  201. {
  202. get
  203. {
  204. return (double)GetValue(MouseOverBackgroundOpacityProperty);
  205. }
  206. set { SetValue(MouseOverBackgroundOpacityProperty, value); }
  207. }
  208. public double MouseDownBackgroundOpacity
  209. {
  210. get
  211. {
  212. return (double)GetValue(MouseDownBackgroundOpacityProperty);
  213. }
  214. set { SetValue(MouseDownBackgroundOpacityProperty, value); }
  215. }
  216. public Brush MouseOverForeground
  217. {
  218. get
  219. {
  220. return (Brush)GetValue(MouseOverForegroundProperty);
  221. }
  222. set { SetValue(MouseOverForegroundProperty, value); }
  223. }
  224. public Brush MouseDownForeground
  225. {
  226. get
  227. {
  228. return (Brush)GetValue(MouseDownForegroundProperty);
  229. }
  230. set { SetValue(MouseDownForegroundProperty, value); }
  231. }
  232. public Brush MouseOverBorderBrush
  233. {
  234. get { return (Brush)GetValue(MouseOverBorderBrushProperty); }
  235. set { SetValue(MouseOverBorderBrushProperty, value); }
  236. }
  237. public Brush MouseDownBorderBrush
  238. {
  239. get { return (Brush)GetValue(MouseDownBorderBrushProperty); }
  240. set { SetValue(MouseDownBorderBrushProperty, value); }
  241. }
  242. public CornerRadius CornerRadius
  243. {
  244. get { return (CornerRadius)GetValue(CornerRadiusProperty); }
  245. set { SetValue(CornerRadiusProperty, value); }
  246. }
  247. public Geometry Icon
  248. {
  249. get { return (Geometry)GetValue(IconProperty); }
  250. set { SetValue(IconProperty, value); }
  251. }
  252. public Brush IconFill
  253. {
  254. get { return (Brush)GetValue(IconFillProperty); }
  255. set { SetValue(IconFillProperty, value); }
  256. }
  257. public double IconOpacity
  258. {
  259. get { return (double)GetValue(IconOpacityProperty); }
  260. set { SetValue(IconOpacityProperty, value); }
  261. }
  262. public Geometry IconChecked
  263. {
  264. get { return (Geometry)GetValue(IconCheckedProperty); }
  265. set { SetValue(IconCheckedProperty, value); }
  266. }
  267. public Brush IconCheckedFill
  268. {
  269. get { return (Brush)GetValue(IconCheckedFillProperty); }
  270. set { SetValue(IconCheckedFillProperty, value); }
  271. }
  272. public double IconCheckedOpacity
  273. {
  274. get { return (double)GetValue(IconCheckedOpacityProperty); }
  275. set { SetValue(IconCheckedOpacityProperty, value); }
  276. }
  277. public Geometry IconMouseOver
  278. {
  279. get { return (Geometry)GetValue(IconMouseOverProperty); }
  280. set { SetValue(IconMouseOverProperty, value); }
  281. }
  282. public Brush IconMouseOverFill
  283. {
  284. get { return (Brush)GetValue(IconMouseOverProperty); }
  285. set { SetValue(IconMouseOverProperty, value); }
  286. }
  287. public double IconMouseOverOpacity
  288. {
  289. get { return (double)GetValue(IconMouseOverProperty); }
  290. set { SetValue(IconMouseOverProperty, value); }
  291. }
  292. public Geometry IconPress
  293. {
  294. get { return (Geometry)GetValue(IconPressProperty); }
  295. set { SetValue(IconPressProperty, value); }
  296. }
  297. public Brush IconPressFill
  298. {
  299. get { return (Brush)GetValue(IconPressFillProperty); }
  300. set { SetValue(IconPressFillProperty, value); }
  301. }
  302. public double IconPressOpacity
  303. {
  304. get { return (double)GetValue(IconPressOpacityProperty); }
  305. set { SetValue(IconPressOpacityProperty, value); }
  306. }
  307. public double IconHeight
  308. {
  309. get { return (double)GetValue(IconHeightProperty); }
  310. set { SetValue(IconHeightProperty, value); }
  311. }
  312. public double IconWidth
  313. {
  314. get { return (double)GetValue(IconWidthProperty); }
  315. set { SetValue(IconWidthProperty, value); }
  316. }
  317. public Orientation IconContentOrientation
  318. {
  319. get { return (Orientation)GetValue(IconContentOrientationProperty); }
  320. set { SetValue(IconContentOrientationProperty, value); }
  321. }
  322. public Thickness IconContentMargin
  323. {
  324. get { return (Thickness)GetValue(IconContentMarginProperty); }
  325. set { SetValue(IconContentMarginProperty, value); }
  326. }
  327. #endregion
  328. }
  329. }