|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- /// <summary>
- /// ConveyBelt2.xaml 的交互逻辑
- /// </summary>
- public partial class ConveyBelt2 : UserControl
- {
- public ConveyBelt2()
- {
- InitializeComponent();
- }
- [Category("运行状态")]
- public bool IsRun
- {
- get { return (bool)GetValue(IsRunProperty); }
- set { SetValue(IsRunProperty, value); }
- }
- public static readonly DependencyProperty IsRunProperty =
- DependencyProperty.Register("IsRun", typeof(bool), typeof(ConveyBelt2), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnRunningChanged)));
-
- private static void OnRunningChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- string status = "Stop";
- if ((bool)e.NewValue)
- {
- if ((d as ConveyBelt2)?.BeltDirection == 0)
- {
- VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
- return;
- }
- else
- {
- VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
- return;
- }
- }
- VisualStateManager.GoToState(d as ConveyBelt2, status, false);
- //VisualStateManager.GoToState(d as ConveyBelt2, (bool)e.NewValue ? "RunState" : "Stop", false);
- }
-
- public double BeltWidth
- {
- get { return (double)GetValue(BeltWidthProperty); }
- set { SetValue(BeltWidthProperty, value); }
- }
- public static readonly DependencyProperty BeltWidthProperty =
- DependencyProperty.Register("BeltWidth", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as ConveyBelt2)?.Refresh();
- }
- public void Refresh()
- {
- PathGeometry geometry = new PathGeometry();
- PathFigure pathFigure = new PathFigure();
- if (BeltHeight > 100)
- {
- pathFigure.StartPoint = new Point(0, 35 + (BeltHeight - 100) / 2);
- pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35 + (BeltHeight - 100) / 2), true));
- }
- else
- {
- pathFigure.StartPoint = new Point(0, 35);
- pathFigure.Segments.Add(new LineSegment(new Point(BeltWidth - 10, 35), true));
- }
- geometry.Figures.Add(pathFigure);
- this.belt.Data = geometry;
- this.belt.StrokeDashOffset = BeltDashOffset;
- this.br.Width = BeltWidth;
- if (BeltHeight > 100)
- {
- this.recDown.Margin = new Thickness(0, BeltHeight - 20, 0, 0);
- }
- else
- {
- this.recDown.Margin = new Thickness(0, 80, 0, 0);
- }
-
- this.belt.StrokeThickness = BeltDashThickess;
- }
-
- public double BeltHeight
- {
- get { return (double)GetValue(BeltHeightProperty); }
- set { SetValue(BeltHeightProperty, value); }
- }
- public static readonly DependencyProperty BeltHeightProperty =
- DependencyProperty.Register("BeltHeight", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
-
- public double BeltDashOffset
- {
- get { return (double)GetValue(BeltDashOffsetProperty); }
- set { SetValue(BeltDashOffsetProperty, value); }
- }
- public static readonly DependencyProperty BeltDashOffsetProperty =
- DependencyProperty.Register("BeltDashOffset", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
-
- public double BeltDashThickess
- {
- get { return (double)GetValue(BeltDashThickessProperty); }
- set { SetValue(BeltDashThickessProperty, value); }
- }
- public static readonly DependencyProperty BeltDashThickessProperty =
- DependencyProperty.Register("BeltDashThickess", typeof(double), typeof(ConveyBelt2), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
- public int BeltDirection
- {
- get { return (int)GetValue(BeltDirectionProperty); }
- set { SetValue(BeltDirectionProperty, value); }
- }
- public static readonly DependencyProperty BeltDirectionProperty =
- DependencyProperty.Register("BeltDirection", typeof(int), typeof(ConveyBelt2), new PropertyMetadata(default(int), new PropertyChangedCallback(OnDirectionChanged)));
-
- private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- string status = "Stop";
- if ((d as ConveyBelt2).IsRun)
- {
- if ((d as ConveyBelt2)?.BeltDirection == 0)
- {
- VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
- return;
- }
- else
- {
- VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
- return;
- }
- }
- VisualStateManager.GoToState(d as ConveyBelt2, status, false);
- //if ((d as ConveyBelt2)?.BeltDirection == 0)
- //{
- // VisualStateManager.GoToState(d as ConveyBelt2, "RightState", false);
- //}
- //else
- //{
- // VisualStateManager.GoToState(d as ConveyBelt2, "LeftState", false);
- //}
-
- }
- }
- }
|