You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
9.5 KiB

  1. using System.Windows;
  2. using System.Windows.Media;
  3. namespace BPA.UIControl
  4. {
  5. /// <summary>
  6. /// 标题帮助类
  7. /// </summary>
  8. public class HeaderHelper
  9. {
  10. /// <summary>
  11. /// 背景色
  12. /// </summary>
  13. public static readonly DependencyProperty BackgroundProperty =
  14. DependencyProperty.RegisterAttached("Background", typeof(Brush), typeof(HeaderHelper), new PropertyMetadata(default));
  15. /// <summary>
  16. /// Gets the background.
  17. /// </summary>
  18. /// <param name="obj">The obj.</param>
  19. /// <returns>A Brush.</returns>
  20. public static Brush GetBackground(DependencyObject obj)
  21. {
  22. return (Brush)obj.GetValue(BackgroundProperty);
  23. }
  24. /// <summary>
  25. /// Sets the background.
  26. /// </summary>
  27. /// <param name="obj">The obj.</param>
  28. /// <param name="value">The value.</param>
  29. public static void SetBackground(DependencyObject obj, Brush value)
  30. {
  31. obj.SetValue(BackgroundProperty, value);
  32. }
  33. /// <summary>
  34. /// 前景色
  35. /// </summary>
  36. public static readonly DependencyProperty ForegroundProperty =
  37. DependencyProperty.RegisterAttached("Foreground", typeof(Brush), typeof(HeaderHelper), new PropertyMetadata(default));
  38. /// <summary>
  39. /// Gets the foreground.
  40. /// </summary>
  41. /// <param name="obj">The obj.</param>
  42. /// <returns>A Brush.</returns>
  43. public static Brush GetForeground(DependencyObject obj)
  44. {
  45. return (Brush)obj.GetValue(ForegroundProperty);
  46. }
  47. /// <summary>
  48. /// Sets the foreground.
  49. /// </summary>
  50. /// <param name="obj">The obj.</param>
  51. /// <param name="value">The value.</param>
  52. public static void SetForeground(DependencyObject obj, Brush value)
  53. {
  54. obj.SetValue(ForegroundProperty, value);
  55. }
  56. /// <summary>
  57. /// 字体
  58. /// </summary>
  59. public static readonly DependencyProperty FontFamilyProperty =
  60. DependencyProperty.RegisterAttached("FontFamily", typeof(FontFamily), typeof(HeaderHelper), new PropertyMetadata(SystemFonts.CaptionFontFamily));
  61. /// <summary>
  62. /// Gets the font family.
  63. /// </summary>
  64. /// <param name="obj">The obj.</param>
  65. /// <returns>A FontFamily.</returns>
  66. public static FontFamily GetFontFamily(DependencyObject obj)
  67. {
  68. return (FontFamily)obj.GetValue(FontFamilyProperty);
  69. }
  70. /// <summary>
  71. /// Sets the font family.
  72. /// </summary>
  73. /// <param name="obj">The obj.</param>
  74. /// <param name="value">The value.</param>
  75. public static void SetFontFamily(DependencyObject obj, FontFamily value)
  76. {
  77. obj.SetValue(FontFamilyProperty, value);
  78. }
  79. /// <summary>
  80. /// 字体大小
  81. /// </summary>
  82. public static readonly DependencyProperty FontSizeProperty =
  83. DependencyProperty.RegisterAttached("FontSize", typeof(double), typeof(HeaderHelper), new PropertyMetadata(SystemFonts.CaptionFontSize));
  84. /// <summary>
  85. /// Gets the font size.
  86. /// </summary>
  87. /// <param name="obj">The obj.</param>
  88. /// <returns>A double.</returns>
  89. public static double GetFontSize(DependencyObject obj)
  90. {
  91. return (double)obj.GetValue(FontSizeProperty);
  92. }
  93. /// <summary>
  94. /// Sets the font size.
  95. /// </summary>
  96. /// <param name="obj">The obj.</param>
  97. /// <param name="value">The value.</param>
  98. public static void SetFontSize(DependencyObject obj, double value)
  99. {
  100. obj.SetValue(FontSizeProperty, value);
  101. }
  102. /// <summary>
  103. /// 字体加粗
  104. /// </summary>
  105. public static readonly DependencyProperty FontWeightProperty =
  106. DependencyProperty.RegisterAttached("FontWeight", typeof(FontWeight), typeof(HeaderHelper), new PropertyMetadata(SystemFonts.CaptionFontWeight));
  107. /// <summary>
  108. /// Gets the font weight.
  109. /// </summary>
  110. /// <param name="obj">The obj.</param>
  111. /// <returns>A FontWeight.</returns>
  112. public static FontWeight GetFontWeight(DependencyObject obj)
  113. {
  114. return (FontWeight)obj.GetValue(FontWeightProperty);
  115. }
  116. /// <summary>
  117. /// Sets the font weight.
  118. /// </summary>
  119. /// <param name="obj">The obj.</param>
  120. /// <param name="value">The value.</param>
  121. public static void SetFontWeight(DependencyObject obj, FontWeight value)
  122. {
  123. obj.SetValue(FontWeightProperty, value);
  124. }
  125. /// <summary>
  126. /// padding
  127. /// </summary>
  128. public static readonly DependencyProperty PaddingProperty =
  129. DependencyProperty.RegisterAttached("Padding", typeof(Thickness), typeof(HeaderHelper), new PropertyMetadata(default));
  130. /// <summary>
  131. /// Gets the padding.
  132. /// </summary>
  133. /// <param name="obj">The obj.</param>
  134. /// <returns>A Thickness.</returns>
  135. public static Thickness GetPadding(DependencyObject obj)
  136. {
  137. return (Thickness)obj.GetValue(PaddingProperty);
  138. }
  139. /// <summary>
  140. /// Sets the padding.
  141. /// </summary>
  142. /// <param name="obj">The obj.</param>
  143. /// <param name="value">The value.</param>
  144. public static void SetPadding(DependencyObject obj, Thickness value)
  145. {
  146. obj.SetValue(PaddingProperty, value);
  147. }
  148. /// <summary>
  149. /// margin
  150. /// </summary>
  151. public static readonly DependencyProperty MarginProperty =
  152. DependencyProperty.RegisterAttached("Margin", typeof(Thickness), typeof(HeaderHelper), new PropertyMetadata(default));
  153. /// <summary>
  154. /// Gets the margin.
  155. /// </summary>
  156. /// <param name="obj">The obj.</param>
  157. /// <returns>A Thickness.</returns>
  158. public static Thickness GetMargin(DependencyObject obj)
  159. {
  160. return (Thickness)obj.GetValue(MarginProperty);
  161. }
  162. /// <summary>
  163. /// Sets the margin.
  164. /// </summary>
  165. /// <param name="obj">The obj.</param>
  166. /// <param name="value">The value.</param>
  167. public static void SetMargin(DependencyObject obj, Thickness value)
  168. {
  169. obj.SetValue(MarginProperty, value);
  170. }
  171. /// <summary>
  172. /// 水平对齐
  173. /// </summary>
  174. public static readonly DependencyProperty HorizontalAlignmentProperty =
  175. DependencyProperty.RegisterAttached("HorizontalAlignment", typeof(HorizontalAlignment), typeof(HeaderHelper), new PropertyMetadata(default));
  176. /// <summary>
  177. /// Gets the horizontal alignment.
  178. /// </summary>
  179. /// <param name="obj">The obj.</param>
  180. /// <returns>A HorizontalAlignment.</returns>
  181. public static HorizontalAlignment GetHorizontalAlignment(DependencyObject obj)
  182. {
  183. return (HorizontalAlignment)obj.GetValue(HorizontalAlignmentProperty);
  184. }
  185. /// <summary>
  186. /// Sets the horizontal alignment.
  187. /// </summary>
  188. /// <param name="obj">The obj.</param>
  189. /// <param name="value">The value.</param>
  190. public static void SetHorizontalAlignment(DependencyObject obj, HorizontalAlignment value)
  191. {
  192. obj.SetValue(HorizontalAlignmentProperty, value);
  193. }
  194. /// <summary>
  195. /// 垂直对齐
  196. /// </summary>
  197. public static readonly DependencyProperty VerticalAlignmentProperty =
  198. DependencyProperty.RegisterAttached("VerticalAlignment", typeof(VerticalAlignment), typeof(HeaderHelper), new PropertyMetadata(default));
  199. /// <summary>
  200. /// Gets the vertical alignment.
  201. /// </summary>
  202. /// <param name="obj">The obj.</param>
  203. /// <returns>A VerticalAlignment.</returns>
  204. public static VerticalAlignment GetVerticalAlignment(DependencyObject obj)
  205. {
  206. return (VerticalAlignment)obj.GetValue(VerticalAlignmentProperty);
  207. }
  208. /// <summary>
  209. /// Sets the vertical alignment.
  210. /// </summary>
  211. /// <param name="obj">The obj.</param>
  212. /// <param name="value">The value.</param>
  213. public static void SetVerticalAlignment(DependencyObject obj, VerticalAlignment value)
  214. {
  215. obj.SetValue(VerticalAlignmentProperty, value);
  216. }
  217. /// <summary>
  218. /// 圆角半径
  219. /// </summary>
  220. public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(
  221. "CornerRadius", typeof(CornerRadius), typeof(HeaderHelper), new PropertyMetadata(default(CornerRadius)));
  222. /// <summary>
  223. /// Sets the corner radius.
  224. /// </summary>
  225. /// <param name="element">The element.</param>
  226. /// <param name="value">The value.</param>
  227. public static void SetCornerRadius(DependencyObject element, CornerRadius value)
  228. {
  229. element.SetValue(CornerRadiusProperty, value);
  230. }
  231. /// <summary>
  232. /// Gets the corner radius.
  233. /// </summary>
  234. /// <param name="element">The element.</param>
  235. /// <returns>A CornerRadius.</returns>
  236. public static CornerRadius GetCornerRadius(DependencyObject element)
  237. {
  238. return (CornerRadius)element.GetValue(CornerRadiusProperty);
  239. }
  240. }
  241. }