|
- using BPASmartClient.Compiler;
- using BPASmartClient.DATABUS;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- 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;
- using System.Windows.Threading;
-
- namespace BPASmartClient.SCADAControl.CustomerControls
- {
- /// <summary>
- /// 常用button
- /// TheButton.xaml 的交互逻辑
- /// </summary>
- public partial class TheButton : Button, IExecutable
- {
- public TheButton()
- {
- InitializeComponent();
- ResourceDictionary languageResDic = new ResourceDictionary();
- languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
- this.Resources.MergedDictionaries.Add(languageResDic);
- this.Loaded += TheButton_Loaded;
- }
-
- private void TheButton_Loaded(object sender, RoutedEventArgs e)
- {
- if (this.ActualWidth <= 20)
- {
- Content = "按钮";
- Width = 80;
- Height = 30;
- }
- }
-
- public string ControlType => "控件";
-
- private bool isExecuteState;
- public bool IsExecuteState
- {
- get { return isExecuteState; }
- set
- {
- isExecuteState = value;
- if (IsExecuteState)
- {
- Register();
- }
- }
- }
-
- [Category("事件")]
- public string ClickExec
- {
- get { return (string)GetValue(ClickExecProperty); }
- set { SetValue(ClickExecProperty, value); }
- }
- public static readonly DependencyProperty ClickExecProperty =
- DependencyProperty.Register("ClickExec", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
-
-
- private void MyButton_Click(object sender, RoutedEventArgs e)
- {
- Config.GetInstance().RunJsScipt(ClickExec);
- try
- {
- if (!string.IsNullOrEmpty(StartPath) && StartPath.Contains(".exe"))
- {
- string path = $"{System.AppDomain.CurrentDomain.BaseDirectory}{StartPath}";
- if (File.Exists(path))
- {
- ProcessStartInfo info = new ProcessStartInfo();
- info.FileName = path;
- info.Arguments = "";
- //info.WindowStyle = ProcessWindowStyle.Minimized;
- Process pro = Process.Start(info);
- pro.WaitForExit();
- }
- }
- }
- catch (Exception ex)
- {
-
- }
-
- }
-
- #region 数据绑定模块
-
- public event EventHandler PropertyChange; //声明一个事件
- /// <summary>
- /// 数据模板
- /// </summary>
- private Dictionary<string, object> DataModel
- {
- get { return (Dictionary<string, object>)GetValue(DataModelProperty); }
- set { SetValue(DataModelProperty, value); }
- }
- private static readonly DependencyProperty DataModelProperty =
- DependencyProperty.Register("DataModel", typeof(Dictionary<string, object>), typeof(TheButton), new PropertyMetadata(new Dictionary<string, object>()));
- /// <summary>
- /// 启动路径
- /// </summary>
- public string StartPath
- {
- get { return (string)GetValue(StartPathProperty); }
- set { SetValue(StartPathProperty, value); }
- }
- public static readonly DependencyProperty StartPathProperty =
- DependencyProperty.Register("StartPath", typeof(string), typeof(TheButton), new PropertyMetadata(string.Empty));
- /// <summary>
- /// 运行事件
- /// </summary>
- public void Register()
- {
- Class_DataBus.GetInstance().BindingAction += BindingActionHeader;
- this.Click += MyButton_Click;
- }
- public void BindingActionHeader(object sender, EventArgs e)
- {
- this.Dispatcher.Invoke((Action)(() =>
- {
- DataModel = Class_DataBus.GetInstance().Dic_RedisDataBinding;
- PropertyChange?.Invoke(this, EventArgs.Empty);
- }));
- }
- #endregion
- }
- }
|