SimulatorPlcInt16IOView.xaml.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Aitex.Common.Util;
  2. using Aitex.Core.UI.MVVM;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. namespace FurnaceSimulator.Views
  6. {
  7. /// <summary>
  8. /// SimulatorPlcInt16IOView.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class SimulatorPlcInt16IOView : UserControl
  11. {
  12. public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
  13. "Port", typeof(int), typeof(SimulatorPlcInt16IOView),
  14. new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
  15. public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
  16. "Source", typeof(string), typeof(SimulatorPlcInt16IOView),
  17. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  18. public static readonly DependencyProperty ModuleProperty = DependencyProperty.Register(
  19. "Module", typeof(string), typeof(SimulatorPlcInt16IOView),
  20. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  21. public static readonly DependencyProperty IoMapFileProperty = DependencyProperty.Register(
  22. "IoMapFile", typeof(string), typeof(SimulatorPlcInt16IOView),
  23. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  24. public int Port
  25. {
  26. get
  27. {
  28. return (int)this.GetValue(PortProperty);
  29. }
  30. set
  31. {
  32. this.SetValue(PortProperty, value);
  33. }
  34. }
  35. public string Source
  36. {
  37. get
  38. {
  39. return (string)this.GetValue(SourceProperty);
  40. }
  41. set
  42. {
  43. this.SetValue(SourceProperty, value);
  44. }
  45. }
  46. public string Module
  47. {
  48. get
  49. {
  50. return (string)this.GetValue(ModuleProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(ModuleProperty, value);
  55. }
  56. }
  57. public string IoMapFile
  58. {
  59. get
  60. {
  61. return (string)this.GetValue(IoMapFileProperty);
  62. }
  63. set
  64. {
  65. this.SetValue(IoMapFileProperty, value);
  66. }
  67. }
  68. private void OnViewLoaded(object sender, RoutedEventArgs e)
  69. {
  70. if (DataContext == null)
  71. {
  72. DataContext = new IoViewModel(Port, Source, $"{PathManager.GetCfgDir()}{IoMapFile}", Module);
  73. (DataContext as TimerViewModelBase).Start();
  74. }
  75. }
  76. public SimulatorPlcInt16IOView()
  77. {
  78. InitializeComponent();
  79. this.Loaded += OnViewLoaded;
  80. }
  81. }
  82. }