GasValveV3.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /// GasValveV3.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class GasValveV3 : UserControl
  21. {
  22. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  23. "Command", typeof(ICommand), typeof(GasValveV3),
  24. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  25. public static readonly DependencyProperty ValveOpenOrientationProperty = DependencyProperty.Register(
  26. "ValveOpenOrientation", typeof (LineOrientation), typeof (GasValveV3),
  27. new FrameworkPropertyMetadata(LineOrientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  28. public static readonly DependencyProperty ValveNameProperty = DependencyProperty.Register(
  29. "ValveName", typeof (string), typeof (GasValveV3),
  30. new FrameworkPropertyMetadata("Undefined", FrameworkPropertyMetadataOptions.AffectsRender));
  31. public static readonly DependencyProperty IsValveOpenProperty = DependencyProperty.Register(
  32. "IsValveOpen", typeof (bool), typeof (GasValveV3),
  33. new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  34. public ICommand Command
  35. {
  36. get
  37. {
  38. return (ICommand)this.GetValue(CommandProperty);
  39. }
  40. set
  41. {
  42. this.SetValue(CommandProperty, value);
  43. }
  44. }
  45. public bool IsValveOpen
  46. {
  47. get { return (bool) GetValue(IsValveOpenProperty); }
  48. set { SetValue(IsValveOpenProperty, value); }
  49. }
  50. public LineOrientation ValveOpenOrientation
  51. {
  52. get { return (LineOrientation) GetValue(ValveOpenOrientationProperty); }
  53. set { SetValue(ValveOpenOrientationProperty, value); }
  54. }
  55. public string ValveName
  56. {
  57. get { return (string) GetValue(ValveNameProperty); }
  58. set { SetValue(ValveNameProperty, value); }
  59. }
  60. public GasValveV3()
  61. {
  62. InitializeComponent();
  63. }
  64. private BitmapSource GetImage(string name)
  65. {
  66. return
  67. new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/Valve/{0}", name)));
  68. }
  69. protected override void OnRender(DrawingContext drawingContext)
  70. {
  71. rotateTransform.Angle = ValveOpenOrientation == LineOrientation.Horizontal ? 0 : 90;
  72. imagePicture.Source = GetImage(IsValveOpen ? "ValveOpenHorizontal.png" : "ValveCloseHorizontal.png");
  73. base.OnRender(drawingContext);
  74. }
  75. private void OpenValve(object sender, RoutedEventArgs e)
  76. {
  77. if (Command == null)
  78. return;
  79. Command.Execute(new object[] { ValveName, GasValveOperation.GVTurnValve, true });
  80. }
  81. private void CloseValve(object sender, RoutedEventArgs e)
  82. {
  83. if (Command == null)
  84. return;
  85. Command.Execute(new object[] { ValveName, GasValveOperation.GVTurnValve, false });
  86. }
  87. }
  88. }