using BPASmartClient.Compiler; using BPASmartClient.SCADAControl; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; 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 { /// /// TheImage.xaml 的交互逻辑 /// public partial class TheImage : Image, IExecutable { public event EventHandler PropertyChange; //声明一个事件 public TheImage() { InitializeComponent(); Stretch = Stretch.Fill; Width = 80; Height = 80; } [Category("事件")] public string ClickExec { get { return (string)GetValue(ClickExecProperty); } set { SetValue(ClickExecProperty, value); } } public static readonly DependencyProperty ClickExecProperty = DependencyProperty.Register("ClickExec", typeof(string), typeof(TheImage), new PropertyMetadata(string.Empty)); /// /// 启动路径 /// public string ImageStartPath { get { return (string)GetValue(StartPathProperty); } set { SetValue(StartPathProperty, value); } } public static readonly DependencyProperty StartPathProperty = DependencyProperty.Register("ImageStartPath", typeof(string), typeof(TheImage), new PropertyMetadata(string.Empty,new PropertyChangedCallback(OnPropertyChanged))); private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as TheImage)?.Refresh(); } private void Refresh() { string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Images\\{ImageStartPath}"; if (!string.IsNullOrEmpty(ImageStartPath) && File.Exists(path)) { Source = new BitmapImage(new Uri(path)); } } public string ControlType => "控件"; private bool isExecuteState; public bool IsExecuteState { get { return isExecuteState; } set { isExecuteState = value; if (IsExecuteState) { Register(); } } } public void Register() { if (!string.IsNullOrEmpty(ImageStartPath)) { string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Images\\{ImageStartPath}"; if (File.Exists(path)) { Source = new BitmapImage(new Uri(path)); } } this.MouseLeftButtonDown += TheImage_MouseLeftButtonDown; } private void TheImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Config.GetInstance().RunJsScipt(ClickExec); } } }