|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using BPASmartClient.Compiler;
-
- 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.SCADAControl.CustomerControls
- {
- /// <summary>
- /// TheCylinder.xaml 的交互逻辑
- /// 气缸
- /// </summary>
- public partial class TheCylinder : UserControl, IExecutable
- {
- #region 临时变量
- Ellipse LeftTog = null;
- Ellipse RightTog = null;
- Storyboard storyboard = new Storyboard();
- #endregion
- public TheCylinder()
- {
- InitializeComponent();
- Width = 389;
- Height = 100;
- this.SizeChanged += TheCylinder_SizeChanged;
- }
-
- #region 事件
- /// <summary>
- /// 字节改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- /// <exception cref="NotImplementedException"></exception>
- private void TheCylinder_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- if (LeftTog == null)
- {
- foreach (Ellipse tb in FindVisualChildren<Ellipse>(this))
- {
- if (tb.Tag != null)
- {
- if (tb.Tag.ToString() == "LeftTog") LeftTog = tb;
- else if (tb.Tag.ToString() == "RightTog") RightTog = tb;
- }
- }
- //storyboard.RepeatBehavior = RepeatBehavior.Forever;
- //DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
- //Storyboard.SetTarget(animation, ellipseControl);
- //Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
- //animation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
- //animation.KeyFrames.Add(new EasingDoubleKeyFrame(180, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
- //animation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));
- //storyboard.Children.Add(animation);
- }
-
- }
- public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
- {
- if (depObj != null)
- {
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
- if (child != null && child is T)
- {
- yield return (T)child;
- }
-
- foreach (T childOfChild in FindVisualChildren<T>(child))
- {
- yield return childOfChild;
- }
- }
- }
- }
- #endregion
-
-
-
-
- #region 属性
- public string ControlType => "控件";
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- IsEnabled = true;
- Focusable = true;
- Register();
- }
- }
- }
- public event EventHandler PropertyChange; //声明一个事件
- public bool LeftTogIsChecked
- {
- get { return (bool)GetValue(LeftTogIsCheckedProperty); }
- set { SetValue(LeftTogIsCheckedProperty, value); }
- }
- public static readonly DependencyProperty LeftTogIsCheckedProperty =
- DependencyProperty.Register("LeftTogIsChecked", typeof(bool), typeof(TheCylinder),
- new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
- public bool RightTogIsChecked
- {
- get { return (bool)GetValue(RightTogIsCheckedProperty); }
- set { SetValue(RightTogIsCheckedProperty, value); }
- }
- public static readonly DependencyProperty RightTogIsCheckedProperty =
- DependencyProperty.Register("RightTogIsChecked", typeof(bool), typeof(TheCylinder),
- new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as TheCylinder)?.Refresh();
- }
- private void Refresh()
- {
- if (LeftTog != null)
- {
- LeftTog.Fill= LeftTogIsChecked?new SolidColorBrush(Colors.Green): new SolidColorBrush(Colors.Red);
- RightTog.Fill = RightTogIsChecked ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red);
- }
- }
- /// <summary>
- /// 数据模板
- /// </summary>
- private Dictionary<string, object> DataModel
- {
- get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
- set { SetValue(DataModelProperty, value); }
- }
- private static readonly DependencyProperty DataModelProperty =
- DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheCylinder), new PropertyMetadata(new Dictionary<string, object>()));
- #endregion
- /// <summary>
- /// 运行事件
- /// </summary>
- public void Register()
- {
- Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
- }
- public void BindingActionHeader(object sender, EventArgs e)
- {
- this.Dispatcher.Invoke((Action)(() =>
- {
- DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
- PropertyChange?.Invoke(this, EventArgs.Empty);
- }));
- }
- }
- }
|