WPF开发冷风机组态及应用
冷风机组件开发和应用
VS2022
.NET6框架
冷风机组件开发演示

WPF主界面设计
WPF主界面托板设计
WPF托板拖动实现
///
/// 视图缩放
///
///
///
private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
{// 获取实际渲染的高度和宽度var w = this.mainView.ActualWidth + e.Delta;var h = this.mainView.ActualHeight + e.Delta;if (w <100) w = 500;if (h <100) h = 100;this.mainView.Height = h;this.mainView.Width = w;// 设置画板缩放的左边位置this.mainView.SetValue(Canvas.LeftProperty, (this.RenderSize.Width - this.mainView.Width) / 2);
}bool _isMoving = false;
Point _point = new Point(0, 0);
double _left =0, _top = 0;private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{_isMoving = true;_point = e.GetPosition(sender as Canvas);_left = double.Parse(this.mainView.GetValue(Canvas.LeftProperty).ToString()!);_top = double.Parse(this.mainView.GetValue(Canvas.TopProperty).ToString()!);
}private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{_isMoving = false;
}private void Canvas_MouseMove(object sender, MouseEventArgs e)
{if (_isMoving){Point currentPoint = e.GetPosition(sender as Canvas);this.mainView.SetValue(LeftProperty, _left + (currentPoint.X - _point.X));this.mainView.SetValue(TopProperty, _top+(currentPoint.Y - _point.Y));}
}
冷风机自定义控件
初始化代码
画风扇托板
画风扇上座弧形
通过Path画风扇
画外壳
画指示灯
VisualStateManager设置运行状态
添加依赖属性
public bool IsRunning
{get { return (bool)GetValue(IsRunningProperty); }set { SetValue(IsRunningProperty, value); }
}// Using a DependencyProperty as the backing store for IsRunning. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsRunningProperty =DependencyProperty.Register("IsRunning", typeof(bool), typeof(CoolingTower), new PropertyMetadata(default(bool),new PropertyChangedCallback(OnRunStateChanged))); private static void OnRunStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{bool state = (bool)e.NewValue;VisualStateManager.GoToState(d as CoolingTower, state ? "RunState" : "StopState", false);
}public bool IsFault
{get { return (bool)GetValue(IsFaultProperty); }set { SetValue(IsFaultProperty, value); }
}// Using a DependencyProperty as the backing store for IsRunning. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsFaultProperty =DependencyProperty.Register("IsFault", typeof(bool), typeof(CoolingTower), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnFaultStateChanged)));private static void OnFaultStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{bool state = (bool)e.NewValue;VisualStateManager.GoToState(d as CoolingTower, state ? "FaultState" : "NormalState", false);
}
自定义流动管道控件
窗口布局
自定义依赖属性
public int Direction
{get { return (int)GetValue(DirectionProperty); }set { SetValue(DirectionProperty, value); }
}// Using a DependencyProperty as the backing store for Direction. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DirectionProperty =DependencyProperty.Register("Direction", typeof(int), typeof(Pipeline), new PropertyMetadata(default(int),new PropertyChangedCallback(OnDirectionChanged)));///
/// 设置状态
///
///
///
///
private static void OnDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{int value = int.Parse(e.NewValue.ToString()!);VisualStateManager.GoToState(d as Pipeline, value == 1 ? "WEFlowState" : "EEFlowState",false);
}///
/// 设置液体颜色
///
public Brush LiquidColor
{get { return (Brush)GetValue(LiquidColorProperty); }set { SetValue(LiquidColorProperty, value); }
}// Using a DependencyProperty as the backing store for LiquidColor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LiquidColorProperty =DependencyProperty.Register("LiquidColor", typeof(Brush), typeof(Pipeline), new PropertyMetadata(Brushes.Red));public int CapRadius
{get { return (int)GetValue(CapRadiusProperty); }set { SetValue(CapRadiusProperty, value); }
}// Using a DependencyProperty as the backing store for CapRadius. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CapRadiusProperty =DependencyProperty.Register("CapRadius", typeof(int), typeof(Pipeline), new PropertyMetadata(0));
界面组装组态应用
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
