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.

112 lines
3.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. namespace BPA.UIControl
  7. {
  8. /// <summary>
  9. /// 加载中
  10. /// </summary>
  11. [TemplatePart(Name = MessageTextPartName, Type = typeof(TextBlock))]
  12. public class Loading : ContentControl
  13. {
  14. /// <summary>
  15. /// 消息文本名称
  16. /// </summary>
  17. public const string MessageTextPartName = "Path_MessageText";
  18. static Loading()
  19. {
  20. DefaultStyleKeyProperty.OverrideMetadata(typeof(Loading), new FrameworkPropertyMetadata(typeof(Loading)));
  21. }
  22. /// <inheritdoc/>
  23. public override void OnApplyTemplate()
  24. {
  25. base.OnApplyTemplate();
  26. }
  27. /// <summary>
  28. /// 边框厚度
  29. /// </summary>
  30. public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register(
  31. "StrokeThickness", typeof(double), typeof(Loading), new PropertyMetadata(default(double)));
  32. /// <summary>
  33. /// 边框厚度
  34. /// </summary>
  35. public double StrokeThickness
  36. {
  37. get { return (double)GetValue(StrokeThicknessProperty); }
  38. set { SetValue(StrokeThicknessProperty, value); }
  39. }
  40. /// <summary>
  41. /// 虚线和间隙的值的集合
  42. /// </summary>
  43. public static readonly DependencyProperty StrokeDashArrayProperty = DependencyProperty.Register(
  44. "StrokeDashArray", typeof(DoubleCollection), typeof(Loading), new PropertyMetadata(default(DoubleCollection)));
  45. /// <summary>
  46. /// 虚线和间隙的值的集合
  47. /// </summary>
  48. public DoubleCollection StrokeDashArray
  49. {
  50. get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
  51. set { SetValue(StrokeDashArrayProperty, value); }
  52. }
  53. /// <summary>
  54. /// 聚焦颜色
  55. /// </summary>
  56. public static readonly DependencyProperty FocusedBrushProperty = DependencyProperty.RegisterAttached(
  57. "FocusedBrush", typeof(Brush), typeof(Loading), new PropertyMetadata(default(Brush)));
  58. /// <summary>
  59. /// 聚焦颜色
  60. /// </summary>
  61. public Brush FocusedBrush
  62. {
  63. get { return (Brush)GetValue(FocusedBrushProperty); }
  64. set { SetValue(FocusedBrushProperty, value); }
  65. }
  66. /// <summary>
  67. /// 进度
  68. /// </summary>
  69. public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(
  70. "Progress", typeof(double), typeof(Loading), new PropertyMetadata(default(double), OnProgressChanged));
  71. /// <summary>
  72. /// 进度
  73. /// </summary>
  74. public double Progress
  75. {
  76. get { return (double)GetValue(ProgressProperty); }
  77. set { SetValue(ProgressProperty, value); }
  78. }
  79. private static void OnProgressChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  80. {
  81. var loading = d as Loading;
  82. loading.StrokeDashArray = new DoubleCollection(new List<double> { (loading.Diameter - loading.StrokeThickness) * Math.PI / loading.StrokeThickness * loading.Progress, double.MaxValue });
  83. }
  84. /// <summary>
  85. /// 直径
  86. /// </summary>
  87. public static readonly DependencyProperty DiameterProperty = DependencyProperty.RegisterAttached(
  88. "Diameter", typeof(double), typeof(Loading), new PropertyMetadata(default(double)));
  89. /// <summary>
  90. /// 直径
  91. /// </summary>
  92. public double Diameter
  93. {
  94. get { return (double)GetValue(DiameterProperty); }
  95. set { SetValue(DiameterProperty, value); }
  96. }
  97. }
  98. }