终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

150 wiersze
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. /// PipeLineBR.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class PipeLineBR : UserControl
  22. {
  23. public PipeLineBR()
  24. {
  25. InitializeComponent();
  26. this.Loaded += (s, e) => { Play(); Refresh(); };
  27. }
  28. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  29. {
  30. (d as PipeLineBR)?.Refresh();
  31. }
  32. private void Refresh()
  33. {
  34. this.mp.StrokeThickness = LineWidth;
  35. Canvas.SetTop(this.mp, 25 - LineWidth / 2);
  36. Canvas.SetLeft(this.mp, 25 - LineWidth / 2);
  37. this.mp.Stroke = LineBrush;
  38. //this.Width = PipeWidth * 2;
  39. //this.Height = PipeWidth * 2;
  40. }
  41. #region 动画相关
  42. Storyboard sb = new Storyboard();
  43. private void Play()
  44. {
  45. sb.Children.Clear();
  46. DoubleAnimation da = new DoubleAnimation();
  47. da.From = 0;
  48. if (Direction == 2) da.To = this.ActualWidth * 3.14 / 4;
  49. else if (Direction == 1) da.To = this.ActualWidth * 3.14 / 4 * -1;
  50. da.RepeatBehavior = RepeatBehavior.Forever;//设置无限循环播放
  51. da.Duration = TimeSpan.FromMilliseconds(Speed * 1000);//设置动画时间
  52. //da.AutoReverse = true;//设置可以反转播放动画
  53. Storyboard.SetTarget(da, mp);//绑定动画
  54. Storyboard.SetTargetProperty(da, new PropertyPath("StrokeDashOffset"));
  55. sb.Children.Add(da);//添加动画
  56. if (Direction != 0) this.mp.Visibility = Visibility.Visible;
  57. sb.Begin();//播放动画
  58. }
  59. private static void OnAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  60. {
  61. (d as PipeLineBR)?.Animation();
  62. }
  63. private void Animation()
  64. {
  65. if (Direction == 0)
  66. {
  67. sb.Stop();
  68. this.mp.Visibility = Visibility.Collapsed;
  69. }
  70. else Play();
  71. }
  72. /// <summary>
  73. /// 液体流向控制
  74. /// 0:停止流动,1正向流动,2反向流动
  75. /// </summary>
  76. public int Direction
  77. {
  78. get { return (int)GetValue(DirectionProperty); }
  79. set { SetValue(DirectionProperty, value); }
  80. }
  81. public static readonly DependencyProperty DirectionProperty =
  82. DependencyProperty.Register("Direction", typeof(int), typeof(PipeLineBR), new(0, new(OnAnimationChanged)));
  83. /// <summary>
  84. /// 液体流动速度
  85. /// 液体流动一次的时间,单位秒
  86. /// </summary>
  87. public float Speed
  88. {
  89. get { return (float)GetValue(SpeedProperty); }
  90. set { SetValue(SpeedProperty, value); }
  91. }
  92. public static readonly DependencyProperty SpeedProperty =
  93. DependencyProperty.Register("Speed", typeof(float), typeof(PipeLineBR), new(8.0f, new(OnAnimationChanged)));
  94. #endregion
  95. /// <summary>
  96. /// 流动宽度
  97. /// </summary>
  98. public int LineWidth
  99. {
  100. get { return (int)GetValue(LineWidthProperty); }
  101. set { SetValue(LineWidthProperty, value); }
  102. }
  103. public static readonly DependencyProperty LineWidthProperty =
  104. DependencyProperty.Register("LineWidth", typeof(int), typeof(PipeLineBR), new(4, new(OnPropertyChanged)));
  105. /// <summary>
  106. /// 流动线条颜色
  107. /// </summary>
  108. public Brush LineBrush
  109. {
  110. get { return (Brush)GetValue(LineBrushProperty); }
  111. set { SetValue(LineBrushProperty, value); }
  112. }
  113. public static readonly DependencyProperty LineBrushProperty =
  114. DependencyProperty.Register("LineBrush", typeof(Brush), typeof(PipeLineBR), new(Brushes.DeepSkyBlue));
  115. public int PipeWidth
  116. {
  117. get { return (int)GetValue(PipeWidthProperty); }
  118. set { SetValue(PipeWidthProperty, value); }
  119. }
  120. public static readonly DependencyProperty PipeWidthProperty =
  121. DependencyProperty.Register("PipeWidth", typeof(int), typeof(PipeLineBR), new(30, new(OnPropertyChanged)));
  122. /// <summary>
  123. /// 管道内壁颜色
  124. /// </summary>
  125. public Color Fill
  126. {
  127. get { return (Color)GetValue(FillProperty); }
  128. set { SetValue(FillProperty, value); }
  129. }
  130. public static readonly DependencyProperty FillProperty =
  131. DependencyProperty.Register("Fill", typeof(Color), typeof(PipeLineBR), new(Brushes.DimGray.Color));
  132. }
  133. }