|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 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;
- }
- }
- }
|