终端一体化运控平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

111 linhas
3.5 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.DATABUS;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Reflection;
  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. using System.Windows.Threading;
  20. namespace BPASmartClient.SCADAControl.CustomerControls
  21. {
  22. /// <summary>
  23. /// 常用button
  24. /// TheButton.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class TheButton : Button, IExecutable
  27. {
  28. public TheButton()
  29. {
  30. InitializeComponent();
  31. ResourceDictionary languageResDic = new ResourceDictionary();
  32. languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
  33. this.Resources.MergedDictionaries.Add(languageResDic);
  34. this.Loaded += TheButton_Loaded;
  35. }
  36. private void TheButton_Loaded(object sender, RoutedEventArgs e)
  37. {
  38. if (this.ActualWidth <= 20)
  39. {
  40. Content = "按钮";
  41. Width = 80;
  42. Height = 30;
  43. }
  44. }
  45. public string ControlType => "控件";
  46. private bool isExecuteState;
  47. public bool IsExecuteState
  48. {
  49. get { return isExecuteState; }
  50. set
  51. {
  52. isExecuteState = value;
  53. if (IsExecuteState)
  54. {
  55. Register();
  56. }
  57. }
  58. }
  59. [Category("事件")]
  60. public string ClickExec
  61. {
  62. get { return (string)GetValue(ClickExecProperty); }
  63. set { SetValue(ClickExecProperty, value); }
  64. }
  65. public static readonly DependencyProperty ClickExecProperty =
  66. DependencyProperty.Register("ClickExec", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
  67. private void MyButton_Click(object sender, RoutedEventArgs e)
  68. {
  69. Config.GetInstance().RunJsScipt(ClickExec);
  70. }
  71. #region 数据绑定模块
  72. public event EventHandler PropertyChange; //声明一个事件
  73. /// <summary>
  74. /// 数据模板
  75. /// </summary>
  76. private Dictionary<string, object> DataModel
  77. {
  78. get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
  79. set { SetValue(DataModelProperty, value); }
  80. }
  81. private static readonly DependencyProperty DataModelProperty =
  82. DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheButton), new PropertyMetadata(new Dictionary<string, object>()));
  83. /// <summary>
  84. /// 运行事件
  85. /// </summary>
  86. public void Register()
  87. {
  88. Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
  89. this.Click += MyButton_Click;
  90. }
  91. public void BindingActionHeader(object sender, EventArgs e)
  92. {
  93. this.Dispatcher.Invoke((Action)(() =>
  94. {
  95. DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
  96. PropertyChange?.Invoke(this, EventArgs.Empty);
  97. }));
  98. }
  99. #endregion
  100. }
  101. }