|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System;
- using System.Collections.Generic;
- 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;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- /// <summary>
- /// PipeLineBL.xaml 的交互逻辑
- /// </summary>
- public partial class PipeLineBL : UserControl
- {
- public PipeLineBL()
- {
- InitializeComponent();
- this.Loaded += (s, e) => { Play(); Refresh(); };
- }
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as PipeLineBL)?.Refresh();
- }
-
- private void Refresh()
- {
- this.mp.StrokeThickness = LineWidth;
- Canvas.SetTop(this.mp, 25 - LineWidth / 2);
- Canvas.SetRight(this.mp, 25 - LineWidth / 2);
- this.mp.Stroke = LineBrush;
- //this.Width = PipeWidth * 2;
- //this.Height = PipeWidth * 2;
- }
-
- #region 动画相关
-
- Storyboard sb = new Storyboard();
- private void Play()
- {
- sb.Children.Clear();
- DoubleAnimation da = new DoubleAnimation();
- da.From = 0;
- if (Direction == 2) da.To = this.ActualWidth * 3.14 / 4;
- else if (Direction == 1) da.To = this.ActualWidth * 3.14 / 4 * -1;
- da.RepeatBehavior = RepeatBehavior.Forever;//设置无限循环播放
- da.Duration = TimeSpan.FromMilliseconds(Speed * 1000);//设置动画时间
- //da.AutoReverse = true;//设置可以反转播放动画
- Storyboard.SetTarget(da, mp);//绑定动画
- Storyboard.SetTargetProperty(da, new PropertyPath("StrokeDashOffset"));
- sb.Children.Add(da);//添加动画
- if (Direction != 0) this.mp.Visibility = Visibility.Visible;
- sb.Begin();//播放动画
- }
-
- private static void OnAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as PipeLineBL)?.Animation();
- }
-
- private void Animation()
- {
- if (Direction == 0)
- {
- sb.Stop();
- this.mp.Visibility = Visibility.Collapsed;
- }
- else Play();
- }
-
- /// <summary>
- /// 液体流向控制
- /// 0:停止流动,1正向流动,2反向流动
- /// </summary>
- public int Direction
- {
- get { return (int)GetValue(DirectionProperty); }
- set { SetValue(DirectionProperty, value); }
- }
- public static readonly DependencyProperty DirectionProperty =
- DependencyProperty.Register("Direction", typeof(int), typeof(PipeLineBL), new(0, new(OnAnimationChanged)));
-
- /// <summary>
- /// 液体流动速度
- /// 液体流动一次的时间,单位秒
- /// </summary>
- public float Speed
- {
- get { return (float)GetValue(SpeedProperty); }
- set { SetValue(SpeedProperty, value); }
- }
- public static readonly DependencyProperty SpeedProperty =
- DependencyProperty.Register("Speed", typeof(float), typeof(PipeLineBL), new(8.0f, new(OnAnimationChanged)));
- #endregion
-
- /// <summary>
- /// 流动线条宽度
- /// </summary>
- public int LineWidth
- {
- get { return (int)GetValue(LineWidthProperty); }
- set { SetValue(LineWidthProperty, value); }
- }
- public static readonly DependencyProperty LineWidthProperty =
- DependencyProperty.Register("LineWidth", typeof(int), typeof(PipeLineBL), new(4, new(OnPropertyChanged)));
-
-
- /// <summary>
- /// 流动线条颜色
- /// </summary>
- public Brush LineBrush
- {
- get { return (Brush)GetValue(LineBrushProperty); }
- set { SetValue(LineBrushProperty, value); }
- }
- public static readonly DependencyProperty LineBrushProperty =
- DependencyProperty.Register("LineBrush", typeof(Brush), typeof(PipeLineBL), new(Brushes.DeepSkyBlue));
-
-
- //public int PipeWidth
- //{
- // get { return (int)GetValue(PipeWidthProperty); }
- // set { SetValue(PipeWidthProperty, value); }
- //}
- //public static readonly DependencyProperty PipeWidthProperty =
- // DependencyProperty.Register("PipeWidth", typeof(int), typeof(PipeLineBL),
- // new PropertyMetadata(30, new PropertyChangedCallback(OnPropertyChanged)));
-
-
- public int PipeWidth
- {
- get { return (int)GetValue(PipeWidthProperty); }
- set { SetValue(PipeWidthProperty, value); }
- }
- public static readonly DependencyProperty PipeWidthProperty =
- DependencyProperty.Register("PipeWidth", typeof(int), typeof(PipeLineBL), new(30, new(OnPropertyChanged)));
-
-
- /// <summary>
- /// 管道内壁颜色
- /// </summary>
- public Color Fill
- {
- get { return (Color)GetValue(FillProperty); }
- set { SetValue(FillProperty, value); }
- }
- public static readonly DependencyProperty FillProperty =
- DependencyProperty.Register("Fill", typeof(Color), typeof(PipeLineBL), new PropertyMetadata(Brushes.DimGray.Color));
-
-
- }
- }
|