|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using BPASmartClient.Compiler;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.SCADAControl.CustomerControls
- {
- /// <summary>
- /// TheRectangle.xaml 的交互逻辑
- /// </summary>
- public partial class TheRectangle : UserControl, IExecutable
- {
- Border LeftTog = null;
-
- public TheRectangle()
- {
- InitializeComponent();
- this.Loaded += TheRectangle_Loaded; ;
- this.SizeChanged += TheRectangle_SizeChanged; ;
- }
-
- private void TheRectangle_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- if (LeftTog == null)
- {
- foreach (Border tb in FindVisualChildren<Border>(this))
- {
- if (tb.Tag != null)
- {
- if (tb.Tag.ToString() == "border") LeftTog = tb;
- }
- }
- }
- }
- 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;
- }
- }
- }
- }
-
- private void TheRectangle_Loaded(object sender, RoutedEventArgs e)
- {
- if (this.ActualWidth <= 20)
- {
- Width = 80;
- Height = 80;
- }
- BKStrokeDashArray.CollectionChanged += BKStrokeDashArray_CollectionChanged;
- }
- private void BKStrokeDashArray_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
- Refresh();
- }
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as TheRectangle)?.Refresh();
- }
- private void Refresh()
- {
- DoubleArray = new DoubleCollection(BKStrokeDashArray);
- }
-
- public Brush BJColor
- {
- get { return (Brush)GetValue(BJColorProperty); }
- set { SetValue(BJColorProperty, value); }
- }
- public static readonly DependencyProperty BJColorProperty =
- DependencyProperty.Register("BJColor", typeof(Brush), typeof(TheRectangle), new PropertyMetadata(new SolidColorBrush(Colors.Transparent)));
- public double BKThickness
- {
- get { return (double)GetValue(BKThicknessProperty); }
- set { SetValue(BKThicknessProperty, value); }
- }
- public static readonly DependencyProperty BKThicknessProperty =
- DependencyProperty.Register("BKThickness", typeof(double), typeof(TheRectangle), new PropertyMetadata(1.0));
- public ObservableCollection<double> BKStrokeDashArray
- {
- get { return (ObservableCollection<double>)GetValue(BKStrokeDashArrayProperty); }
- set { SetValue(BKStrokeDashArrayProperty, value); }
- }
- public static readonly DependencyProperty BKStrokeDashArrayProperty =
- DependencyProperty.Register("BKStrokeDashArray", typeof(ObservableCollection<double>), typeof(TheRectangle), new PropertyMetadata(new ObservableCollection<double>(), new PropertyChangedCallback(OnPropertyChanged)));
- public DoubleCollection DoubleArray
- {
- get { return (DoubleCollection)GetValue(DoubleArrayProperty); }
- set { SetValue(DoubleArrayProperty, value); }
- }
- public static readonly DependencyProperty DoubleArrayProperty =
- DependencyProperty.Register("DoubleArray", typeof(DoubleCollection), typeof(TheRectangle), new PropertyMetadata(new DoubleCollection()));
-
- public event EventHandler PropertyChange; //声明一个事件
- public string ControlType => "控件";
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- Register();
- }
- }
- }
- // <summary>
- /// 运行事件
- /// </summary>
- public void Register()
- {
-
- }
- }
- }
|