|
- using BPASmartClient.Compiler;
- using BPASmartClient.SCADAControl;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- 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
- {
- /// <summary>
- /// TheTabControl.xaml 的交互逻辑
- /// </summary>
- public partial class TheTabControl : TabControl, IExecutable
- {
- public event EventHandler PropertyChange; //声明一个事件
- public TheTabControl()
- {
- InitializeComponent();
- ResourceDictionary languageResDic = new ResourceDictionary();
- languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
- this.Resources.MergedDictionaries.Add(languageResDic);
- Width = 150;
- Height = 150;
- this.Loaded += TheTabControl_Loaded;
- this.SelectionChanged += TheTabControl_SelectionChanged;
- }
-
- private void TheTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- try
- {
- object _header = (this.SelectedItem as TabItem)?.Header;
- TabItems?.ToList().ForEach(par =>
- {
- if (_header!=null && par.Header == (string)_header)
- {
- if(!string.IsNullOrEmpty(par.ClickStr))
- Config.GetInstance().RunJsScipt(par.ClickStr);
- }
- });
- }
- catch (Exception ex)
- {
-
- throw;
- }
-
- }
-
- private void TheTabControl_Loaded(object sender, RoutedEventArgs e)
- {
- TabItems.CollectionChanged += TabItems_CollectionChanged;
- }
-
- private void TabItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
- this.Items.Clear();
- if (TabItems.Count > 0)
- {
- try
- {
- TabItemsStr = JsonConvert.SerializeObject(TabItems);
- TabItems?.ToList().ForEach(item => {
-
- this.Items.Add(new TabItem { Header = item.Header, Style = (FindResource("TheTabItem") as Style) });
- });
- }
- catch (Exception ex)
- {
- }
- }
- }
-
- public string ControlType => "控件";
-
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- Register();
- }
- }
- }
-
- /// <summary>
- /// 注册需要处理的事件
- /// </summary>
- public void Register()
- {
- if (!string.IsNullOrEmpty(TabItemsStr))
- {
- try
- {
- TabItems = JsonConvert.DeserializeObject<ObservableCollection<TheTabItemModel>>(TabItemsStr);
- }
- catch (Exception ex)
- {
-
- }
- }
- }
-
- #region 属性
- [Category("名称[自动生成]")]
- private string TabItemsStr
- {
- get { return (string)GetValue(TabItemsStrProperty); }
- set { SetValue(TabItemsStrProperty, value); }
- }
- private static readonly DependencyProperty TabItemsStrProperty =
- DependencyProperty.Register("TabItemsStr", typeof(string), typeof(TheTabControl), new PropertyMetadata(string.Empty, new PropertyChangedCallback(onEventReceiveNameListStrChanged)));
- private static void onEventReceiveNameListStrChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheTabControl)?.TabItemsStrPropertyRefresh();
- [Category("集合")]
- public ObservableCollection<TheTabItemModel> TabItems
- {
- get { return (ObservableCollection<TheTabItemModel>)GetValue(TabItemsProperty); }
- set { SetValue(TabItemsProperty, value); }
- }
- private static readonly DependencyProperty TabItemsProperty =
- DependencyProperty.Register("TabItems", typeof(ObservableCollection<TheTabItemModel>), typeof(TheTabControl), new PropertyMetadata(new ObservableCollection<TheTabItemModel>(), new PropertyChangedCallback(onEventNameListChanged)));
- private static void onEventNameListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheTabControl)?.TabItemsPropertyRefresh();
- public void TabItemsStrPropertyRefresh()
- {
- if (!string.IsNullOrEmpty(TabItemsStr))
- {
- try
- {
- // TabItems = JsonConvert.DeserializeObject<ObservableCollection<TheTabItemModel>>(TabItemsStr);
- }
- catch (Exception ex)
- {
-
- }
- }
- }
- public void TabItemsPropertyRefresh()
- {
-
- }
- #endregion
-
-
-
- }
-
- public class TheTabItemModel
- {
- /// <summary>
- /// 序号
- /// </summary>
- public int SortID { get; set; }
- /// <summary>
- /// 标题
- /// </summary>
- public string Header { get; set; }
- /// <summary>
- /// 单机事件
- /// </summary>
- public string ClickStr { get; set; }
- public TheTabItemModel()
- {
- SortID = 0;
- }
- }
- }
|