No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

273 líneas
10 KiB

  1. using BPA.UIControl.Commons.KnownBoxes;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. namespace BPA.UIControl
  5. {
  6. /// <summary>
  7. /// 控件帮助基类
  8. /// </summary>
  9. public class ControlHelper
  10. {
  11. /// <summary>
  12. /// 圆角半径
  13. /// </summary>
  14. public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(
  15. "CornerRadius", typeof(CornerRadius), typeof(ControlHelper), new PropertyMetadata(default(CornerRadius)));
  16. /// <summary>
  17. /// Sets the corner radius.
  18. /// </summary>
  19. /// <param name="element">The element.</param>
  20. /// <param name="value">The value.</param>
  21. public static void SetCornerRadius(DependencyObject element, CornerRadius value)
  22. {
  23. element.SetValue(CornerRadiusProperty, value);
  24. }
  25. /// <summary>
  26. /// Gets the corner radius.
  27. /// </summary>
  28. /// <param name="element">The element.</param>
  29. /// <returns>A CornerRadius.</returns>
  30. public static CornerRadius GetCornerRadius(DependencyObject element)
  31. {
  32. return (CornerRadius)element.GetValue(CornerRadiusProperty);
  33. }
  34. /// <summary>
  35. /// 聚焦颜色
  36. /// </summary>
  37. public static readonly DependencyProperty FocusedBrushProperty = DependencyProperty.RegisterAttached(
  38. "FocusedBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  39. /// <summary>
  40. /// Sets the focused brush.
  41. /// </summary>
  42. /// <param name="element">The element.</param>
  43. /// <param name="value">The value.</param>
  44. public static void SetFocusedBrush(DependencyObject element, Brush value)
  45. {
  46. element.SetValue(FocusedBrushProperty, value);
  47. }
  48. /// <summary>
  49. /// Gets the focused brush.
  50. /// </summary>
  51. /// <param name="element">The element.</param>
  52. /// <returns>A Brush.</returns>
  53. public static Brush GetFocusedBrush(DependencyObject element)
  54. {
  55. return (Brush)element.GetValue(FocusedBrushProperty);
  56. }
  57. /// <summary>
  58. /// 聚焦前景色
  59. /// </summary>
  60. public static readonly DependencyProperty FocusedForegroundBrushProperty = DependencyProperty.RegisterAttached(
  61. "FocusedForegroundBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  62. /// <summary>
  63. /// Sets the focused foreground brush.
  64. /// </summary>
  65. /// <param name="element">The element.</param>
  66. /// <param name="value">The value.</param>
  67. public static void SetFocusedForegroundBrush(DependencyObject element, Brush value)
  68. {
  69. element.SetValue(FocusedForegroundBrushProperty, value);
  70. }
  71. /// <summary>
  72. /// Gets the focused foreground brush.
  73. /// </summary>
  74. /// <param name="element">The element.</param>
  75. /// <returns>A Brush.</returns>
  76. public static Brush GetFocusedForegroundBrush(DependencyObject element)
  77. {
  78. return (Brush)element.GetValue(FocusedForegroundBrushProperty);
  79. }
  80. /// <summary>
  81. /// 聚焦边框颜色
  82. /// </summary>
  83. public static readonly DependencyProperty FocusBorderBrushProperty = DependencyProperty.RegisterAttached(
  84. "FocusBorderBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  85. /// <summary>
  86. /// Sets the focus border brush.
  87. /// </summary>
  88. /// <param name="element">The element.</param>
  89. /// <param name="value">The value.</param>
  90. public static void SetFocusBorderBrush(DependencyObject element, Brush value)
  91. {
  92. element.SetValue(FocusBorderBrushProperty, value);
  93. }
  94. /// <summary>
  95. /// Gets the focus border brush.
  96. /// </summary>
  97. /// <param name="element">The element.</param>
  98. /// <returns>A Brush.</returns>
  99. public static Brush GetFocusBorderBrush(DependencyObject element)
  100. {
  101. return (Brush)element.GetValue(FocusBorderBrushProperty);
  102. }
  103. /// <summary>
  104. /// 聚焦边框厚度
  105. /// </summary>
  106. public static readonly DependencyProperty FocusBorderThicknessProperty = DependencyProperty.RegisterAttached(
  107. "FocusBorderThickness", typeof(Thickness), typeof(ControlHelper), new PropertyMetadata(default(Thickness)));
  108. /// <summary>
  109. /// Sets the focus border thickness.
  110. /// </summary>
  111. /// <param name="element">The element.</param>
  112. /// <param name="value">The value.</param>
  113. public static void SetFocusBorderThickness(DependencyObject element, Thickness value)
  114. {
  115. element.SetValue(FocusBorderThicknessProperty, value);
  116. }
  117. /// <summary>
  118. /// Gets the focus border thickness.
  119. /// </summary>
  120. /// <param name="element">The element.</param>
  121. /// <returns>A Thickness.</returns>
  122. public static Thickness GetFocusBorderThickness(DependencyObject element)
  123. {
  124. return (Thickness)element.GetValue(FocusBorderThicknessProperty);
  125. }
  126. /// <summary>
  127. /// 鼠标悬停颜色
  128. /// </summary>
  129. public static readonly DependencyProperty MouseOverBrushProperty = DependencyProperty.RegisterAttached(
  130. "MouseOverBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  131. /// <summary>
  132. /// Sets the mouse over brush.
  133. /// </summary>
  134. /// <param name="element">The element.</param>
  135. /// <param name="value">The value.</param>
  136. public static void SetMouseOverBrush(DependencyObject element, Brush value)
  137. {
  138. element.SetValue(MouseOverBrushProperty, value);
  139. }
  140. /// <summary>
  141. /// Gets the mouse over brush.
  142. /// </summary>
  143. /// <param name="element">The element.</param>
  144. /// <returns>A Brush.</returns>
  145. public static Brush GetMouseOverBrush(DependencyObject element)
  146. {
  147. return (Brush)element.GetValue(MouseOverBrushProperty);
  148. }
  149. /// <summary>
  150. /// 按下颜色
  151. /// </summary>
  152. public static readonly DependencyProperty PressedBrushProperty = DependencyProperty.RegisterAttached(
  153. "PressedBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  154. /// <summary>
  155. /// Sets the pressed brush.
  156. /// </summary>
  157. /// <param name="element">The element.</param>
  158. /// <param name="value">The value.</param>
  159. public static void SetPressedBrush(DependencyObject element, Brush value)
  160. {
  161. element.SetValue(PressedBrushProperty, value);
  162. }
  163. /// <summary>
  164. /// Gets the pressed brush.
  165. /// </summary>
  166. /// <param name="element">The element.</param>
  167. /// <returns>A Brush.</returns>
  168. public static Brush GetPressedBrush(DependencyObject element)
  169. {
  170. return (Brush)element.GetValue(PressedBrushProperty);
  171. }
  172. /// <summary>
  173. /// 选中颜色
  174. /// </summary>
  175. public static readonly DependencyProperty SelectedBrushProperty = DependencyProperty.RegisterAttached(
  176. "SelectedBrush", typeof(Brush), typeof(ControlHelper), new PropertyMetadata(default(Brush)));
  177. /// <summary>
  178. /// Sets the Selected brush.
  179. /// </summary>
  180. /// <param name="element">The element.</param>
  181. /// <param name="value">The value.</param>
  182. public static void SetSelectedBrush(DependencyObject element, Brush value)
  183. {
  184. element.SetValue(SelectedBrushProperty, value);
  185. }
  186. /// <summary>
  187. /// Gets the Selected brush.
  188. /// </summary>
  189. /// <param name="element">The element.</param>
  190. /// <returns>A Brush.</returns>
  191. public static Brush GetSelectedBrush(DependencyObject element)
  192. {
  193. return (Brush)element.GetValue(SelectedBrushProperty);
  194. }
  195. /// <summary>
  196. /// 是否聚焦
  197. /// </summary>
  198. public static readonly DependencyProperty IsKeyBoardFocusedProperty = DependencyProperty.RegisterAttached(
  199. "IsKeyBoardFocused", typeof(bool), typeof(ControlHelper), new PropertyMetadata(BooleanBoxes.FalseBox));
  200. /// <summary>
  201. /// Gets the is key board focused.
  202. /// </summary>
  203. /// <param name="obj">The obj.</param>
  204. /// <returns>A bool.</returns>
  205. public static bool GetIsKeyBoardFocused(DependencyObject obj)
  206. {
  207. return (bool)obj.GetValue(IsKeyBoardFocusedProperty);
  208. }
  209. /// <summary>
  210. /// Sets the is key board focused.
  211. /// </summary>
  212. /// <param name="obj">The obj.</param>
  213. /// <param name="value">If true, value.</param>
  214. public static void SetIsKeyBoardFocused(DependencyObject obj, bool value)
  215. {
  216. obj.SetValue(IsKeyBoardFocusedProperty, BooleanBoxes.Box(value));
  217. }
  218. /// <summary>
  219. /// 遮罩透明度
  220. /// </summary>
  221. public static readonly DependencyProperty MaskOpacityProperty = DependencyProperty.RegisterAttached(
  222. "MaskOpacity", typeof(double), typeof(ControlHelper), new PropertyMetadata(0.6));
  223. /// <summary>
  224. /// Gets the mask opacity.
  225. /// </summary>
  226. /// <param name="obj">The obj.</param>
  227. /// <returns>A double.</returns>
  228. public static double GetMaskOpacity(DependencyObject obj)
  229. {
  230. return (double)obj.GetValue(MaskOpacityProperty);
  231. }
  232. /// <summary>
  233. /// Sets the mask opacity.
  234. /// </summary>
  235. /// <param name="obj">The obj.</param>
  236. /// <param name="value">The value.</param>
  237. public static void SetMaskOpacity(DependencyObject obj, double value)
  238. {
  239. obj.SetValue(MaskOpacityProperty, value);
  240. }
  241. }
  242. }