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

153 line
5.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Animation;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace BPASmartClient.CustomResource.UserControls
  17. {
  18. /// <summary>
  19. /// PipeLineV.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class PipeLineV : UserControl
  22. {
  23. public PipeLineV()
  24. {
  25. InitializeComponent();
  26. this.SizeChanged += PipeLineV_SizeChanged;
  27. this.Loaded += (s, e) => { Play(); Refresh(); };
  28. }
  29. private void PipeLineV_SizeChanged(object sender, SizeChangedEventArgs e)
  30. {
  31. LineChange();
  32. }
  33. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  34. {
  35. (d as PipeLineV)?.Refresh();
  36. }
  37. private void Refresh()
  38. {
  39. LineChange();
  40. this.mp.StrokeThickness = LineWidth;
  41. this.mp.Stroke = LineBrush;
  42. }
  43. private void LineChange()
  44. {
  45. PathGeometry geometry1 = new PathGeometry();
  46. PathFigure pathFigure1 = new PathFigure();
  47. pathFigure1.StartPoint = new Point(this.ActualWidth / 2, 0);
  48. pathFigure1.Segments.Add(new LineSegment(new Point(this.ActualWidth / 2, this.ActualHeight), true));
  49. geometry1.Figures.Add(pathFigure1);
  50. this.mp.Data = geometry1;
  51. }
  52. #region 动画相关
  53. Storyboard sb = new Storyboard();
  54. private void Play()
  55. {
  56. sb.Children.Clear();
  57. DoubleAnimation da = new DoubleAnimation();
  58. da.From = 0;
  59. if (Direction == 2) da.To = this.ActualHeight;
  60. else if (Direction == 1) da.To = this.ActualHeight * -1;
  61. da.RepeatBehavior = RepeatBehavior.Forever;//设置无限循环播放
  62. da.Duration = TimeSpan.FromMilliseconds(Speed * 1000);//设置动画时间
  63. //da.AutoReverse = true;//设置可以反转播放动画
  64. Storyboard.SetTarget(da, mp);//绑定动画
  65. Storyboard.SetTargetProperty(da, new PropertyPath("StrokeDashOffset"));
  66. sb.Children.Add(da);//添加动画
  67. if (Direction != 0) this.mp.Visibility = Visibility.Visible;
  68. sb.Begin();//播放动画
  69. }
  70. private static void OnAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  71. {
  72. (d as PipeLineV)?.Animation();
  73. }
  74. private void Animation()
  75. {
  76. if (Direction == 0)
  77. {
  78. sb.Stop();
  79. this.mp.Visibility = Visibility.Collapsed;
  80. }
  81. else Play();
  82. }
  83. /// <summary>
  84. /// 液体流向控制
  85. /// 0:停止流动,1正向流动,2反向流动
  86. /// </summary>
  87. public int Direction
  88. {
  89. get { return (int)GetValue(DirectionProperty); }
  90. set { SetValue(DirectionProperty, value); }
  91. }
  92. public static readonly DependencyProperty DirectionProperty =
  93. DependencyProperty.Register("Direction", typeof(int), typeof(PipeLineV), new(0, new(OnAnimationChanged)));
  94. /// <summary>
  95. /// 液体流动速度
  96. /// 液体流动一次的时间,单位秒
  97. /// </summary>
  98. public float Speed
  99. {
  100. get { return (float)GetValue(SpeedProperty); }
  101. set { SetValue(SpeedProperty, value); }
  102. }
  103. public static readonly DependencyProperty SpeedProperty =
  104. DependencyProperty.Register("Speed", typeof(float), typeof(PipeLineV), new(8.0f, new(OnAnimationChanged)));
  105. #endregion
  106. /// <summary>
  107. /// 流动宽度
  108. /// </summary>
  109. public int LineWidth
  110. {
  111. get { return (int)GetValue(LineWidthProperty); }
  112. set { SetValue(LineWidthProperty, value); }
  113. }
  114. public static readonly DependencyProperty LineWidthProperty =
  115. DependencyProperty.Register("LineWidth", typeof(int), typeof(PipeLineV), new(4, new(OnPropertyChanged)));
  116. /// <summary>
  117. /// 流动线条颜色
  118. /// </summary>
  119. public Brush LineBrush
  120. {
  121. get { return (Brush)GetValue(LineBrushProperty); }
  122. set { SetValue(LineBrushProperty, value); }
  123. }
  124. public static readonly DependencyProperty LineBrushProperty =
  125. DependencyProperty.Register("LineBrush", typeof(Brush), typeof(PipeLineV), new(Brushes.DeepSkyBlue));
  126. /// <summary>
  127. /// 管道内壁颜色
  128. /// </summary>
  129. public Color Fill
  130. {
  131. get { return (Color)GetValue(FillProperty); }
  132. set { SetValue(FillProperty, value); }
  133. }
  134. public static readonly DependencyProperty FillProperty =
  135. DependencyProperty.Register("Fill", typeof(Color), typeof(PipeLineV), new(Brushes.DimGray.Color));
  136. }
  137. }