PressureTransducer.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.UI.ControlDataContext;
  15. namespace Aitex.Core.UI.Control
  16. {
  17. /// <summary>
  18. /// Interaction logic for PressureTransducer.xaml
  19. /// tag为指定的命令
  20. /// </summary>
  21. public partial class PressureTransducer : UserControl
  22. {
  23. public PressureTransducer()
  24. {
  25. InitializeComponent();
  26. }
  27. //public static readonly DependencyProperty PtNameProperty = DependencyProperty.Register(
  28. // "PtName", typeof(object), typeof(PressureTransducer),
  29. // new FrameworkPropertyMetadata("PT", FrameworkPropertyMetadataOptions.AffectsRender));
  30. //public static readonly DependencyProperty CheckOkProperty = DependencyProperty.Register(
  31. // "CheckOk", typeof(object), typeof(PressureTransducer),
  32. // new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  33. //public static readonly DependencyProperty DPDataProperty = DependencyProperty.Register(
  34. // "DPData", typeof(object), typeof(PressureTransducer),
  35. // new FrameworkPropertyMetadata("DPT", FrameworkPropertyMetadataOptions.AffectsRender));
  36. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  37. "Command", typeof(ICommand), typeof(PressureTransducer),
  38. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  39. public ICommand Command
  40. {
  41. get
  42. {
  43. return GetValue(CommandProperty) as ICommand;
  44. }
  45. set
  46. {
  47. SetValue(CommandProperty, value);
  48. }
  49. }
  50. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  51. "DeviceData", typeof(PressureTransducerDataItem), typeof(PressureTransducer),
  52. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  53. // SetBinding(PocketRawDataChart.PocketInfoProperty, new Binding("PocketInfo") { });
  54. // SetBinding(PocketRawDataChart.SetDummyCommandProperty, new Binding("SetDummyCommand") { });
  55. public PressureTransducerDataItem DeviceData
  56. {
  57. get
  58. {
  59. return (PressureTransducerDataItem)this.GetValue(DeviceDataProperty);
  60. }
  61. set
  62. {
  63. this.SetValue(DeviceDataProperty, value);
  64. }
  65. }
  66. //bool innerEnableClick = true;
  67. //public bool EnableClick
  68. //{
  69. // get { return innerEnableClick; }
  70. // set { innerEnableClick = value; }
  71. //}
  72. /// <summary>
  73. /// render override
  74. /// </summary>
  75. /// <param name="drawingContext"></param>
  76. protected override void OnRender(DrawingContext drawingContext)
  77. {
  78. base.OnRender(drawingContext);
  79. if (DeviceData != null)
  80. {
  81. this.ToolTip = "当前状态:" + (DeviceData.IsEnable ? "打开" : "关闭");
  82. this.label1.Content = DeviceData.Value.ToString("f1");
  83. this.EllipsePT.Fill = DeviceData.IsEnable ? Brushes.Green : Brushes.MediumSlateBlue;
  84. }
  85. }
  86. private void TurnOnValve(object sender, RoutedEventArgs e)
  87. {
  88. Execute(true);
  89. }
  90. private void TurnOffValve(object sender, RoutedEventArgs e)
  91. {
  92. Execute(false);
  93. }
  94. private void Execute(bool value)
  95. {
  96. if (Command != null)
  97. Command.Execute(new object[] { DeviceData.DeviceName, PressureTransducerOperation.DPEnable, value });
  98. }
  99. private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  100. {
  101. if (DeviceData == null)
  102. return;
  103. //if (!EnableClick) return;
  104. //bool tempcheck = false;
  105. //bool.TryParse(CheckOk + "", out tempcheck);
  106. ContextMenu mouseClickMenu = new ContextMenu();
  107. MenuItem item = new MenuItem();
  108. item.Header = DeviceData.DisplayName;
  109. item.Background = Brushes.Gray;
  110. item.Foreground = Brushes.White;
  111. item.IsEnabled = false;
  112. mouseClickMenu.Items.Add(item);
  113. if (DeviceData.IsEnable)
  114. CreateMenuItem("关闭", TurnOffValve, mouseClickMenu);
  115. else
  116. CreateMenuItem("打开", TurnOnValve, mouseClickMenu);
  117. }
  118. void CreateMenuItem(string headerName, RoutedEventHandler clickfunc, ContextMenu mouseClickMenu)
  119. {
  120. MenuItem item = new MenuItem();
  121. item.Header = headerName;
  122. item.Click += clickfunc;
  123. item.Tag = this.Tag;
  124. mouseClickMenu.Items.Add(item);
  125. mouseClickMenu.IsOpen = true;
  126. }
  127. }
  128. }