终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

102 rindas
3.2 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace BPASmartClient.SCADAControl.CustomerControls
  20. {
  21. /// <summary>
  22. /// TheImage.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class TheImage : Image, IExecutable
  25. {
  26. public event EventHandler PropertyChange; //声明一个事件
  27. public TheImage()
  28. {
  29. InitializeComponent();
  30. Stretch = Stretch.Fill;
  31. Width = 80;
  32. Height = 80;
  33. }
  34. [Category("事件")]
  35. public string ClickExec
  36. {
  37. get { return (string)GetValue(ClickExecProperty); }
  38. set { SetValue(ClickExecProperty, value); }
  39. }
  40. public static readonly DependencyProperty ClickExecProperty =
  41. DependencyProperty.Register("ClickExec", typeof(string), typeof(TheImage), new PropertyMetadata(string.Empty));
  42. /// <summary>
  43. /// 启动路径
  44. /// </summary>
  45. public string ImageStartPath
  46. {
  47. get { return (string)GetValue(StartPathProperty); }
  48. set { SetValue(StartPathProperty, value); }
  49. }
  50. public static readonly DependencyProperty StartPathProperty =
  51. DependencyProperty.Register("ImageStartPath", typeof(string), typeof(TheImage), new PropertyMetadata(string.Empty,new PropertyChangedCallback(OnPropertyChanged)));
  52. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  53. {
  54. (d as TheImage)?.Refresh();
  55. }
  56. private void Refresh()
  57. {
  58. string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Images\\{ImageStartPath}";
  59. if (!string.IsNullOrEmpty(ImageStartPath) && File.Exists(path))
  60. {
  61. Source = new BitmapImage(new Uri(path));
  62. }
  63. }
  64. public string ControlType => "控件";
  65. private bool isExecuteState;
  66. public bool IsExecuteState
  67. {
  68. get { return isExecuteState; }
  69. set
  70. {
  71. isExecuteState = value;
  72. if (IsExecuteState)
  73. {
  74. Register();
  75. }
  76. }
  77. }
  78. public void Register()
  79. {
  80. if (!string.IsNullOrEmpty(ImageStartPath))
  81. {
  82. string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}Images\\{ImageStartPath}";
  83. if (File.Exists(path))
  84. {
  85. Source = new BitmapImage(new Uri(path));
  86. }
  87. }
  88. this.MouseLeftButtonDown += TheImage_MouseLeftButtonDown;
  89. }
  90. private void TheImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  91. {
  92. Config.GetInstance().RunJsScipt(ClickExec);
  93. }
  94. }
  95. }