终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

158 строки
5.2 KiB

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