终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

184 satır
5.9 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.SCADAControl;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace BPASmartClient.SCADAControl.CustomerControls
  21. {
  22. /// <summary>
  23. /// TheTabControl.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class TheTabControl : TabControl, IExecutable
  26. {
  27. public event EventHandler PropertyChange; //声明一个事件
  28. public TheTabControl()
  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. Width = 150;
  35. Height = 150;
  36. this.Loaded += TheTabControl_Loaded;
  37. this.SelectionChanged += TheTabControl_SelectionChanged;
  38. }
  39. private void TheTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
  40. {
  41. try
  42. {
  43. object _header = (this.SelectedItem as TabItem)?.Header;
  44. TabItems?.ToList().ForEach(par =>
  45. {
  46. if (_header!=null && par.Header == (string)_header)
  47. {
  48. if(!string.IsNullOrEmpty(par.ClickStr))
  49. Config.GetInstance().RunJsScipt(par.ClickStr);
  50. }
  51. });
  52. }
  53. catch (Exception ex)
  54. {
  55. throw;
  56. }
  57. }
  58. private void TheTabControl_Loaded(object sender, RoutedEventArgs e)
  59. {
  60. TabItems.CollectionChanged += TabItems_CollectionChanged;
  61. }
  62. private void TabItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  63. {
  64. this.Items.Clear();
  65. if (TabItems.Count > 0)
  66. {
  67. try
  68. {
  69. TabItemsStr = JsonConvert.SerializeObject(TabItems);
  70. TabItems?.ToList().ForEach(item => {
  71. this.Items.Add(new TabItem { Header = item.Header, Style = (FindResource("TheTabItem") as Style) });
  72. });
  73. }
  74. catch (Exception ex)
  75. {
  76. }
  77. }
  78. }
  79. public string ControlType => "控件";
  80. private bool isExecuteState;
  81. public bool IsExecuteState
  82. {
  83. get { return isExecuteState; }
  84. set
  85. {
  86. isExecuteState = value;
  87. if (IsExecuteState)
  88. {
  89. Register();
  90. }
  91. }
  92. }
  93. /// <summary>
  94. /// 注册需要处理的事件
  95. /// </summary>
  96. public void Register()
  97. {
  98. if (!string.IsNullOrEmpty(TabItemsStr))
  99. {
  100. try
  101. {
  102. TabItems = JsonConvert.DeserializeObject<ObservableCollection<TheTabItemModel>>(TabItemsStr);
  103. }
  104. catch (Exception ex)
  105. {
  106. }
  107. }
  108. }
  109. #region 属性
  110. [Category("名称[自动生成]")]
  111. private string TabItemsStr
  112. {
  113. get { return (string)GetValue(TabItemsStrProperty); }
  114. set { SetValue(TabItemsStrProperty, value); }
  115. }
  116. private static readonly DependencyProperty TabItemsStrProperty =
  117. DependencyProperty.Register("TabItemsStr", typeof(string), typeof(TheTabControl), new PropertyMetadata(string.Empty, new PropertyChangedCallback(onEventReceiveNameListStrChanged)));
  118. private static void onEventReceiveNameListStrChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheTabControl)?.TabItemsStrPropertyRefresh();
  119. [Category("集合")]
  120. public ObservableCollection<TheTabItemModel> TabItems
  121. {
  122. get { return (ObservableCollection<TheTabItemModel>)GetValue(TabItemsProperty); }
  123. set { SetValue(TabItemsProperty, value); }
  124. }
  125. private static readonly DependencyProperty TabItemsProperty =
  126. DependencyProperty.Register("TabItems", typeof(ObservableCollection<TheTabItemModel>), typeof(TheTabControl), new PropertyMetadata(new ObservableCollection<TheTabItemModel>(), new PropertyChangedCallback(onEventNameListChanged)));
  127. private static void onEventNameListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheTabControl)?.TabItemsPropertyRefresh();
  128. public void TabItemsStrPropertyRefresh()
  129. {
  130. if (!string.IsNullOrEmpty(TabItemsStr))
  131. {
  132. try
  133. {
  134. // TabItems = JsonConvert.DeserializeObject<ObservableCollection<TheTabItemModel>>(TabItemsStr);
  135. }
  136. catch (Exception ex)
  137. {
  138. }
  139. }
  140. }
  141. public void TabItemsPropertyRefresh()
  142. {
  143. }
  144. #endregion
  145. }
  146. public class TheTabItemModel
  147. {
  148. /// <summary>
  149. /// 序号
  150. /// </summary>
  151. public int SortID { get; set; }
  152. /// <summary>
  153. /// 标题
  154. /// </summary>
  155. public string Header { get; set; }
  156. /// <summary>
  157. /// 单机事件
  158. /// </summary>
  159. public string ClickStr { get; set; }
  160. public TheTabItemModel()
  161. {
  162. SortID = 0;
  163. }
  164. }
  165. }