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
{
///
/// TheRectangle.xaml 的交互逻辑
///
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(this))
{
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "border") LeftTog = tb;
}
}
}
}
public static IEnumerable FindVisualChildren(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(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 BKStrokeDashArray
{
get { return (ObservableCollection)GetValue(BKStrokeDashArrayProperty); }
set { SetValue(BKStrokeDashArrayProperty, value); }
}
public static readonly DependencyProperty BKStrokeDashArrayProperty =
DependencyProperty.Register("BKStrokeDashArray", typeof(ObservableCollection), typeof(TheRectangle), new PropertyMetadata(new ObservableCollection(), 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();
}
}
}
//
/// 运行事件
///
public void Register()
{
}
}
}