终端一体化运控平台
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.
 
 
 

188 line
5.9 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows.Media;
  7. namespace BeDesignerSCADA.CustomerControls
  8. {
  9. /// <summary>
  10. /// 波浪进度条
  11. /// </summary>
  12. [TemplatePart(Name = ElementWave, Type = typeof(FrameworkElement))]
  13. [TemplatePart(Name = ElementClip, Type = typeof(FrameworkElement))]
  14. public class WaveProgressBar : RangeBase, IExecutable
  15. {
  16. public event EventHandler PropertyChange; //声明一个事件
  17. private const string ElementWave = "PART_Wave";
  18. private const string ElementClip = "PART_Clip";
  19. private FrameworkElement _waveElement;
  20. private const double TranslateTransformMinY = -20;
  21. private double _translateTransformYRange;
  22. private TranslateTransform _translateTransform;
  23. public WaveProgressBar()
  24. {
  25. Loaded += (s, e) => UpdateWave(Value);
  26. SetCurrentValue(WidthProperty, 200d);
  27. SetCurrentValue(HeightProperty, 200d);
  28. SetCurrentValue(ValueProperty, 50d);
  29. }
  30. static WaveProgressBar()
  31. {
  32. FocusableProperty.OverrideMetadata(typeof(WaveProgressBar),
  33. new FrameworkPropertyMetadata(ValueBoxes.FalseBox));
  34. MaximumProperty.OverrideMetadata(typeof(WaveProgressBar),
  35. new FrameworkPropertyMetadata(ValueBoxes.Double100Box));
  36. }
  37. protected override void OnValueChanged(double oldValue, double newValue)
  38. {
  39. base.OnValueChanged(oldValue, newValue);
  40. UpdateWave(newValue);
  41. }
  42. private void UpdateWave(double value)
  43. {
  44. if (_translateTransform == null || IsVerySmall(Maximum)) return;
  45. var scale = 1 - value / Maximum;
  46. var y = _translateTransformYRange * scale + TranslateTransformMinY;
  47. _translateTransform.Y = y;
  48. }
  49. public static bool IsVerySmall(double value) => Math.Abs(value) < 1E-06;
  50. public override void OnApplyTemplate()
  51. {
  52. base.OnApplyTemplate();
  53. _waveElement = GetTemplateChild(ElementWave) as FrameworkElement;
  54. var clipElement = GetTemplateChild(ElementClip) as FrameworkElement;
  55. if (_waveElement != null && clipElement != null)
  56. {
  57. _translateTransform = new TranslateTransform
  58. {
  59. Y = clipElement.Height
  60. };
  61. _translateTransformYRange = clipElement.Height - TranslateTransformMinY;
  62. _waveElement.RenderTransform = new TransformGroup
  63. {
  64. Children = { _translateTransform }
  65. };
  66. }
  67. }
  68. public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
  69. "Text", typeof(string), typeof(WaveProgressBar), new PropertyMetadata(default(string)));
  70. public string Text
  71. {
  72. get => (string)GetValue(TextProperty);
  73. set => SetValue(TextProperty, value);
  74. }
  75. public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(
  76. "ShowText", typeof(bool), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.TrueBox));
  77. public bool ShowText
  78. {
  79. get => (bool)GetValue(ShowTextProperty);
  80. set => SetValue(ShowTextProperty, ValueBoxes.BooleanBox(value));
  81. }
  82. public static readonly DependencyProperty WaveFillProperty = DependencyProperty.Register(
  83. "WaveFill", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
  84. public Brush WaveFill
  85. {
  86. get => (Brush)GetValue(WaveFillProperty);
  87. set => SetValue(WaveFillProperty, value);
  88. }
  89. public static readonly DependencyProperty WaveThicknessProperty = DependencyProperty.Register(
  90. "WaveThickness", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.Double0Box));
  91. public double WaveThickness
  92. {
  93. get => (double)GetValue(WaveThicknessProperty);
  94. set => SetValue(WaveThicknessProperty, value);
  95. }
  96. public static readonly DependencyProperty WaveStrokeProperty = DependencyProperty.Register(
  97. "WaveStroke", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
  98. public Brush WaveStroke
  99. {
  100. get => (Brush)GetValue(WaveStrokeProperty);
  101. set => SetValue(WaveStrokeProperty, value);
  102. }
  103. public string ControlType => "控件";
  104. private bool isExecuteState;
  105. public bool IsExecuteState
  106. {
  107. get { return isExecuteState; }
  108. set
  109. {
  110. isExecuteState = value;
  111. if (IsExecuteState)
  112. {
  113. Register();
  114. }
  115. }
  116. }
  117. public void Register()
  118. {
  119. }
  120. }
  121. internal static class ValueBoxes
  122. {
  123. internal static object TrueBox = true;
  124. internal static object FalseBox = false;
  125. internal static object Double0Box = .0;
  126. internal static object Double01Box = .1;
  127. internal static object Double1Box = 1.0;
  128. internal static object Double10Box = 10.0;
  129. internal static object Double20Box = 20.0;
  130. internal static object Double100Box = 100.0;
  131. internal static object Double200Box = 200.0;
  132. internal static object Double300Box = 300.0;
  133. internal static object DoubleNeg1Box = -1.0;
  134. internal static object Int0Box = 0;
  135. internal static object Int1Box = 1;
  136. internal static object Int2Box = 2;
  137. internal static object Int5Box = 5;
  138. internal static object Int99Box = 99;
  139. internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
  140. }
  141. }