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

191 lines
6.2 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 BPASmartClient.SCADAControl.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. ResourceDictionary languageResDic = new ResourceDictionary();
  26. languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
  27. this.Resources.MergedDictionaries.Add(languageResDic);
  28. Loaded += (s, e) => UpdateWave(Value);
  29. SetCurrentValue(WidthProperty, 200d);
  30. SetCurrentValue(HeightProperty, 200d);
  31. SetCurrentValue(ValueProperty, 50d);
  32. }
  33. static WaveProgressBar()
  34. {
  35. FocusableProperty.OverrideMetadata(typeof(WaveProgressBar),
  36. new FrameworkPropertyMetadata(ValueBoxes.FalseBox));
  37. MaximumProperty.OverrideMetadata(typeof(WaveProgressBar),
  38. new FrameworkPropertyMetadata(ValueBoxes.Double100Box));
  39. }
  40. protected override void OnValueChanged(double oldValue, double newValue)
  41. {
  42. base.OnValueChanged(oldValue, newValue);
  43. UpdateWave(newValue);
  44. }
  45. private void UpdateWave(double value)
  46. {
  47. if (_translateTransform == null || IsVerySmall(Maximum)) return;
  48. var scale = 1 - value / Maximum;
  49. var y = _translateTransformYRange * scale + TranslateTransformMinY;
  50. _translateTransform.Y = y;
  51. }
  52. public static bool IsVerySmall(double value) => Math.Abs(value) < 1E-06;
  53. public override void OnApplyTemplate()
  54. {
  55. base.OnApplyTemplate();
  56. _waveElement = GetTemplateChild(ElementWave) as FrameworkElement;
  57. var clipElement = GetTemplateChild(ElementClip) as FrameworkElement;
  58. if (_waveElement != null && clipElement != null)
  59. {
  60. _translateTransform = new TranslateTransform
  61. {
  62. Y = clipElement.Height
  63. };
  64. _translateTransformYRange = clipElement.Height - TranslateTransformMinY;
  65. _waveElement.RenderTransform = new TransformGroup
  66. {
  67. Children = { _translateTransform }
  68. };
  69. }
  70. }
  71. public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
  72. "Text", typeof(string), typeof(WaveProgressBar), new PropertyMetadata(default(string)));
  73. public string Text
  74. {
  75. get => (string)GetValue(TextProperty);
  76. set => SetValue(TextProperty, value);
  77. }
  78. public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(
  79. "ShowText", typeof(bool), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.TrueBox));
  80. public bool ShowText
  81. {
  82. get => (bool)GetValue(ShowTextProperty);
  83. set => SetValue(ShowTextProperty, ValueBoxes.BooleanBox(value));
  84. }
  85. public static readonly DependencyProperty WaveFillProperty = DependencyProperty.Register(
  86. "WaveFill", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
  87. public Brush WaveFill
  88. {
  89. get => (Brush)GetValue(WaveFillProperty);
  90. set => SetValue(WaveFillProperty, value);
  91. }
  92. public static readonly DependencyProperty WaveThicknessProperty = DependencyProperty.Register(
  93. "WaveThickness", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.Double0Box));
  94. public double WaveThickness
  95. {
  96. get => (double)GetValue(WaveThicknessProperty);
  97. set => SetValue(WaveThicknessProperty, value);
  98. }
  99. public static readonly DependencyProperty WaveStrokeProperty = DependencyProperty.Register(
  100. "WaveStroke", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
  101. public Brush WaveStroke
  102. {
  103. get => (Brush)GetValue(WaveStrokeProperty);
  104. set => SetValue(WaveStrokeProperty, value);
  105. }
  106. public string ControlType => "控件";
  107. private bool isExecuteState;
  108. public bool IsExecuteState
  109. {
  110. get { return isExecuteState; }
  111. set
  112. {
  113. isExecuteState = value;
  114. if (IsExecuteState)
  115. {
  116. Register();
  117. }
  118. }
  119. }
  120. public void Register()
  121. {
  122. }
  123. }
  124. internal static class ValueBoxes
  125. {
  126. internal static object TrueBox = true;
  127. internal static object FalseBox = false;
  128. internal static object Double0Box = .0;
  129. internal static object Double01Box = .1;
  130. internal static object Double1Box = 1.0;
  131. internal static object Double10Box = 10.0;
  132. internal static object Double20Box = 20.0;
  133. internal static object Double100Box = 100.0;
  134. internal static object Double200Box = 200.0;
  135. internal static object Double300Box = 300.0;
  136. internal static object DoubleNeg1Box = -1.0;
  137. internal static object Int0Box = 0;
  138. internal static object Int1Box = 1;
  139. internal static object Int2Box = 2;
  140. internal static object Int5Box = 5;
  141. internal static object Int99Box = 99;
  142. internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
  143. }
  144. }