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
{
///
/// TheEllipse.xaml 的交互逻辑
///
public partial class TheEllipse : UserControl, IExecutable
{
Ellipse LeftTog = null;
public TheEllipse()
{
InitializeComponent();
this.Loaded += TheEllipse_Loaded; ; ;
this.SizeChanged += TheEllipse_SizeChanged; ; ;
}
private void TheEllipse_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (LeftTog == null)
{
foreach (Ellipse tb in FindVisualChildren(this))
{
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "Ellipse") 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 TheEllipse_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();
}
public Brush BJColor
{
get { return (Brush)GetValue(BJColorProperty); }
set { SetValue(BJColorProperty, value); }
}
public static readonly DependencyProperty BJColorProperty =
DependencyProperty.Register("BJColor", typeof(Brush), typeof(TheEllipse), 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(TheEllipse), 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(TheEllipse), 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(TheEllipse), new PropertyMetadata(new DoubleCollection()));
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as TheEllipse)?.Refresh();
}
private void Refresh()
{
DoubleArray = new DoubleCollection(BKStrokeDashArray);
}
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()
{
}
}
}