SimThrottleValveView.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using Aitex.Core.UI.MVVM;
  4. using Aitex.Core.Utilities;
  5. using MECF.Framework.Simulator.Core.Commons;
  6. using MECF.Framework.Simulator.Core.LoadPorts;
  7. namespace MECF.Framework.Simulator.Core.ThrottleValves.KITZ
  8. {
  9. /// <summary>
  10. /// OmronCIDRWView.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class SimThrottleValveView : UserControl
  13. {
  14. public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
  15. "Port", typeof(string), typeof(SimThrottleValveView),
  16. new FrameworkPropertyMetadata("COM9", FrameworkPropertyMetadataOptions.AffectsRender));
  17. public string Port
  18. {
  19. get
  20. {
  21. return (string)this.GetValue(PortProperty);
  22. }
  23. set
  24. {
  25. this.SetValue(PortProperty, value);
  26. }
  27. }
  28. public SimThrottleValveView()
  29. {
  30. InitializeComponent();
  31. this.Loaded += OnViewLoaded;
  32. }
  33. private void OnViewLoaded(object sender, RoutedEventArgs e)
  34. {
  35. if (DataContext == null)
  36. {
  37. DataContext = new SimThrottleValveViewModel( Port );
  38. (DataContext as TimerViewModelBase).Start();
  39. }
  40. }
  41. }
  42. class SimThrottleValveViewModel : SerialPortDeviceViewModel
  43. {
  44. public string Title
  45. {
  46. get { return "KITZ Throttle Valve Simulator"; }
  47. }
  48. private SimThrottleValve _reader;
  49. //private string _value;
  50. [IgnorePropertyChange]
  51. public string ResultValue
  52. {
  53. get
  54. {
  55. return _reader.ResultValue;
  56. }
  57. set
  58. {
  59. _reader.ResultValue = value;
  60. }
  61. }
  62. public SimThrottleValveViewModel(string port) : base("SimThrottleValveViewModel")
  63. {
  64. _reader = new SimThrottleValve(port);
  65. Init(_reader);
  66. }
  67. }
  68. }