|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using BPA.Helper;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- /// <summary>
- /// TechnologyInstrument.xaml 的交互逻辑
- /// </summary>
- public partial class TechnologyInstrument : UserControl
- {
- public TechnologyInstrument()
- {
- InitializeComponent();
- this.Loaded += (o, e) => { DrawScale(); };
- }
-
-
- /// <summary>
- /// 单位
- /// </summary>
- public string Unit
- {
- get { return (string)GetValue(UnitProperty); }
- set { SetValue(UnitProperty, value); }
- }
- public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(TechnologyInstrument), new("%"));
-
-
- public string Title
- {
- get { return (string)GetValue(TitleProperty); }
- set { SetValue(TitleProperty, value); }
- }
- public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(TechnologyInstrument), new("Title"));
-
-
- public double Value
- {
- get { return (double)GetValue(ValueProperty); }
- set { SetValue(ValueProperty, value); }
- }
- public static readonly DependencyProperty ValueProperty =
- DependencyProperty.Register("Value", typeof(double), typeof(TechnologyInstrument),
- new PropertyMetadata(default(double), new PropertyChangedCallback(OnValuePropertyChanged)));
-
- public double Minimum
- {
- get { return (double)GetValue(MinimumProperty); }
- set { SetValue(MinimumProperty, value); }
- }
- public static readonly DependencyProperty MinimumProperty =
- DependencyProperty.Register("Minimum", typeof(double), typeof(TechnologyInstrument),
- new PropertyMetadata(0d, new PropertyChangedCallback(OnPropertyChanged)));
-
- public double Maximum
- {
- get { return (double)GetValue(MaximumProperty); }
- set { SetValue(MaximumProperty, value); }
- }
- public static readonly DependencyProperty MaximumProperty =
- DependencyProperty.Register("Maximum", typeof(double), typeof(TechnologyInstrument),
- new PropertyMetadata(100d, new PropertyChangedCallback(OnPropertyChanged)));
-
-
- /// <summary>
- /// 大刻度分段间隔数
- /// </summary>
- public int LargeScaleInterval
- {
- get { return (int)GetValue(LargeScaleIntervalProperty); }
- set { SetValue(LargeScaleIntervalProperty, value); }
- }
- public static readonly DependencyProperty LargeScaleIntervalProperty =
- DependencyProperty.Register("LargeScaleInterval", typeof(int), typeof(TechnologyInstrument),
- new PropertyMetadata(10, new PropertyChangedCallback(OnPropertyChanged)));
-
-
- /// <summary>
- /// 小刻度分段数
- /// </summary>
- public int SmallScaleInterval
- {
- get { return (int)GetValue(SmallScaleIntervalProperty); }
- set { SetValue(SmallScaleIntervalProperty, value); }
- }
- public static readonly DependencyProperty SmallScaleIntervalProperty =
- DependencyProperty.Register("SmallScaleInterval", typeof(int), typeof(TechnologyInstrument),
- new PropertyMetadata(5, new PropertyChangedCallback(OnPropertyChanged)));
-
-
-
- public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as TechnologyInstrument)?.DrawScale();
- }
-
- public static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as TechnologyInstrument)?.Refresh();
- }
-
- private void Refresh()
- {
- DoubleAnimation da1 = new DoubleAnimation(Value.Scale(Maximum, Minimum, 100, 0), new Duration(TimeSpan.FromMilliseconds(500)));//指定动画的值
- this.ellips.BeginAnimation(EllipseProgressBehavior.ProgressProperty, da1);//指定动画对象
-
- var TempProgress = Value.Scale(Maximum, Minimum, 100, 0);
-
- //指针动画显示
- DoubleAnimation da = new DoubleAnimation(TempProgress.Scale(100, 0, 315, 45), new Duration(TimeSpan.FromMilliseconds(500)));//指定动画的值
- this.rtfPath.BeginAnimation(RotateTransform.AngleProperty, da);//指定动画对象
-
- }
-
- /// <summary>
- /// 画表盘的刻度
- /// </summary>
- private void DrawScale()
- {
- if (this.canvasPlate == null || Maximum <= Minimum) return;
- this.canvasPlate.Children.Clear();
-
-
- //double step = 270.0 / (this.Maximum - this.Minimum);//获取大刻度的角度
- //step = 270.0 / Interval;
- //int TextScale = (int)this.Minimum;
- for (int i = 0; i <= LargeScaleInterval; i++)
- {
- double calcValue = i * Maximum / LargeScaleInterval * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180;
- Line lineScale = new Line();
- //注意Math.Cos和Math.Sin的参数是弧度,记得将角度转为弧度制
- lineScale.X1 = 150 - 130 * Math.Cos(calcValue);
- lineScale.Y1 = 150 - 130 * Math.Sin(calcValue);
- lineScale.Stroke = new SolidColorBrush(Colors.White);
- lineScale.StrokeThickness = 2;
-
- //添加刻度值
- TextBlock txtScale = new TextBlock();
- txtScale.Text = Math.Truncate((this.Minimum + (this.Maximum - this.Minimum) / LargeScaleInterval * i)).ToString();
- txtScale.Width = 34;
- txtScale.TextAlignment = TextAlignment.Center;
- txtScale.Foreground = new SolidColorBrush(Colors.White);
- txtScale.RenderTransform = new RotateTransform() { Angle = 45, CenterX = 17, CenterY = 8 };
- txtScale.FontSize = 18;
- Canvas.SetLeft(txtScale, 150 - 105 * Math.Cos(calcValue) - 17);
- Canvas.SetTop(txtScale, 150 - 105 * Math.Sin(calcValue) - 10);
-
- this.canvasPlate.Children.Add(txtScale);
-
- lineScale.X2 = 150 - 140 * Math.Cos(calcValue);
- lineScale.Y2 = 150 - 140 * Math.Sin(calcValue);
- this.canvasPlate.Children.Add(lineScale);
- }
-
-
-
- //小刻度绘制
- double ste = (this.Maximum - this.Minimum) / LargeScaleInterval / SmallScaleInterval;
- for (int i = 0; i < (this.Maximum - this.Minimum) / ste; i++)
- {
- double calcValue = i * ste * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180;
-
- Line lineScale = new Line();
-
- lineScale.X1 = 150 - 130 * Math.Cos(calcValue);
- lineScale.Y1 = 150 - 130 * Math.Sin(calcValue);
- lineScale.Stroke = new SolidColorBrush(Colors.White);
- lineScale.StrokeThickness = 1;
- lineScale.Opacity = 0.5;
-
-
- lineScale.X2 = 150 - 140 * Math.Cos(calcValue);
- lineScale.Y2 = 150 - 140 * Math.Sin(calcValue);
- this.canvasPlate.Children.Add(lineScale);
- }
-
-
-
- return;
-
- for (double i = 0; i <= this.Maximum - this.Minimum; i++)
- {
- //添加刻度线
- Line lineScale = new Line();
-
- if (i % 10 == 0)//大刻度
- {
- //注意Math.Cos和Math.Sin的参数是弧度,记得将角度转为弧度制
- lineScale.X1 = 150 - 130 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- lineScale.Y1 = 150 - 130 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- lineScale.Stroke = new SolidColorBrush(Colors.White);
- lineScale.StrokeThickness = 2;
-
- //添加刻度值
- TextBlock txtScale = new TextBlock();
- txtScale.Text = (i + this.Minimum).ToString();
- txtScale.Width = 34;
- txtScale.TextAlignment = TextAlignment.Center;
- txtScale.Foreground = new SolidColorBrush(Colors.White);
- txtScale.RenderTransform = new RotateTransform() { Angle = 45, CenterX = 17, CenterY = 8 };
- txtScale.FontSize = 18;
-
- Canvas.SetLeft(txtScale, 150 - 105 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180) - 17);
- Canvas.SetTop(txtScale, 150 - 105 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180) - 10);
-
- this.canvasPlate.Children.Add(txtScale);
- }
- else//小刻度
- {
- lineScale.X1 = 150 - 130 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- lineScale.Y1 = 150 - 130 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- lineScale.Stroke = new SolidColorBrush(Colors.White);
- lineScale.StrokeThickness = 1;
- lineScale.Opacity = 0.5;
- }
-
- lineScale.X2 = 150 - 140 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- lineScale.Y2 = 150 - 140 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- this.canvasPlate.Children.Add(lineScale);
- }
-
-
-
- //if (this.canvasPlate == null) return;
- //this.canvasPlate.Children.Clear();
-
- //for (double i = 0; i <= this.Maximum - this.Minimum; i++)
- //{
- // //添加刻度线
- // Line lineScale = new Line();
-
- // if (i % 10 == 0)
- // {
- // //注意Math.Cos和Math.Sin的参数是弧度,记得将角度转为弧度制
- // lineScale.X1 = 200 - 170 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // lineScale.Y1 = 200 - 170 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // lineScale.Stroke = new SolidColorBrush(Colors.White);
- // lineScale.StrokeThickness = 2;
-
- // //添加刻度值
- // TextBlock txtScale = new TextBlock();
- // txtScale.Text = (i + this.Minimum).ToString();
- // txtScale.Width = 34;
- // txtScale.TextAlignment = TextAlignment.Center;
- // txtScale.Foreground = new SolidColorBrush(Colors.White);
- // txtScale.RenderTransform = new RotateTransform() { Angle = 45, CenterX = 17, CenterY = 8 };
- // txtScale.FontSize = 18;
-
- // Canvas.SetLeft(txtScale, 200 - 155 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180) - 17);
- // Canvas.SetTop(txtScale, 200 - 155 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180) - 10);
-
- // this.canvasPlate.Children.Add(txtScale);
- // }
- // else
- // {
- // lineScale.X1 = 200 - 180 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // lineScale.Y1 = 200 - 180 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // lineScale.Stroke = new SolidColorBrush(Colors.White);
- // lineScale.StrokeThickness = 1;
- // lineScale.Opacity = 0.5;
- // }
-
- // lineScale.X2 = 200 - 190 * Math.Cos(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // lineScale.Y2 = 200 - 190 * Math.Sin(i * (270 / (this.Maximum - this.Minimum)) * Math.PI / 180);
- // this.canvasPlate.Children.Add(lineScale);
- //}
-
-
-
- }
-
-
- }
- }
|