|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using BPASmartClient.Compiler;
- using BPASmartClient.SCADAControl;
- using System;
- using System.Windows;
- using System.Windows.Controls.Primitives;
- using System.Windows.Media;
-
- namespace BPASmartClient.SCADAControl.CustomerControls
- {
- /// <summary>
- /// 波浪进度条
- /// </summary>
- [TemplatePart(Name = ElementWave, Type = typeof(FrameworkElement))]
- [TemplatePart(Name = ElementClip, Type = typeof(FrameworkElement))]
- public class WaveProgressBar : RangeBase, IExecutable
- {
- public event EventHandler PropertyChange; //声明一个事件
-
- private const string ElementWave = "PART_Wave";
-
- private const string ElementClip = "PART_Clip";
-
- private FrameworkElement _waveElement;
-
- private const double TranslateTransformMinY = -20;
-
- private double _translateTransformYRange;
-
- private TranslateTransform _translateTransform;
-
- public WaveProgressBar()
- {
- ResourceDictionary languageResDic = new ResourceDictionary();
- languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
- this.Resources.MergedDictionaries.Add(languageResDic);
- Loaded += (s, e) => UpdateWave(Value);
- SetCurrentValue(WidthProperty, 200d);
- SetCurrentValue(HeightProperty, 200d);
- SetCurrentValue(ValueProperty, 50d);
- }
-
- static WaveProgressBar()
- {
- FocusableProperty.OverrideMetadata(typeof(WaveProgressBar),
- new FrameworkPropertyMetadata(ValueBoxes.FalseBox));
- MaximumProperty.OverrideMetadata(typeof(WaveProgressBar),
- new FrameworkPropertyMetadata(ValueBoxes.Double100Box));
- }
-
- protected override void OnValueChanged(double oldValue, double newValue)
- {
- base.OnValueChanged(oldValue, newValue);
-
- UpdateWave(newValue);
- }
-
- private void UpdateWave(double value)
- {
- if (_translateTransform == null || IsVerySmall(Maximum)) return;
- var scale = 1 - value / Maximum;
- var y = _translateTransformYRange * scale + TranslateTransformMinY;
- _translateTransform.Y = y;
- }
-
- public static bool IsVerySmall(double value) => Math.Abs(value) < 1E-06;
-
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
-
- _waveElement = GetTemplateChild(ElementWave) as FrameworkElement;
- var clipElement = GetTemplateChild(ElementClip) as FrameworkElement;
-
- if (_waveElement != null && clipElement != null)
- {
- _translateTransform = new TranslateTransform
- {
- Y = clipElement.Height
- };
- _translateTransformYRange = clipElement.Height - TranslateTransformMinY;
- _waveElement.RenderTransform = new TransformGroup
- {
- Children = { _translateTransform }
- };
- }
- }
-
- public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
- "Text", typeof(string), typeof(WaveProgressBar), new PropertyMetadata(default(string)));
-
- public string Text
- {
- get => (string)GetValue(TextProperty);
- set => SetValue(TextProperty, value);
- }
-
- public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(
- "ShowText", typeof(bool), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.TrueBox));
-
- public bool ShowText
- {
- get => (bool)GetValue(ShowTextProperty);
- set => SetValue(ShowTextProperty, ValueBoxes.BooleanBox(value));
- }
-
- public static readonly DependencyProperty WaveFillProperty = DependencyProperty.Register(
- "WaveFill", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
-
- public Brush WaveFill
- {
- get => (Brush)GetValue(WaveFillProperty);
- set => SetValue(WaveFillProperty, value);
- }
-
- public static readonly DependencyProperty WaveThicknessProperty = DependencyProperty.Register(
- "WaveThickness", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.Double0Box));
-
- public double WaveThickness
- {
- get => (double)GetValue(WaveThicknessProperty);
- set => SetValue(WaveThicknessProperty, value);
- }
-
- public static readonly DependencyProperty WaveStrokeProperty = DependencyProperty.Register(
- "WaveStroke", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush)));
-
- public Brush WaveStroke
- {
- get => (Brush)GetValue(WaveStrokeProperty);
- set => SetValue(WaveStrokeProperty, value);
- }
-
- public string ControlType => "控件";
-
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- Register();
- }
- }
- }
-
- public void Register()
- {
- }
- }
-
- internal static class ValueBoxes
- {
- internal static object TrueBox = true;
-
- internal static object FalseBox = false;
-
- internal static object Double0Box = .0;
-
- internal static object Double01Box = .1;
-
- internal static object Double1Box = 1.0;
-
- internal static object Double10Box = 10.0;
-
- internal static object Double20Box = 20.0;
-
- internal static object Double100Box = 100.0;
-
- internal static object Double200Box = 200.0;
-
- internal static object Double300Box = 300.0;
-
- internal static object DoubleNeg1Box = -1.0;
-
- internal static object Int0Box = 0;
-
- internal static object Int1Box = 1;
-
- internal static object Int2Box = 2;
-
- internal static object Int5Box = 5;
-
- internal static object Int99Box = 99;
-
- internal static object BooleanBox(bool value) => value ? TrueBox : FalseBox;
- }
- }
|