SimulatorIo1View.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows.Data;
  7. using Aitex.Common.Util;
  8. using Aitex.Core.UI.MVVM;
  9. using MECF.Framework.Common.IOCore;
  10. using VirgoSimulator.Instances;
  11. namespace VirgoSimulator.Views
  12. {
  13. /// <summary>
  14. /// IoView.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class SimulatorIo1View : UserControl
  17. {
  18. public SimulatorIo1View()
  19. {
  20. InitializeComponent();
  21. var ioFileName = "_ioDefineVirgo.xml";
  22. if (AppSettingHelper.IsVirgoR()) ioFileName = "_ioDefineVirgo_R.xml";
  23. DataContext = new IoViewModel(6731, "PMA.PLC", PathManager.GetCfgDir() + ioFileName, "PMA");
  24. this.IsVisibleChanged += IOView_IsVisibleChanged;
  25. }
  26. private void IOView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  27. {
  28. if (this.DataContext == null)
  29. {
  30. }
  31. (DataContext as TimerViewModelBase).EnableTimer(IsVisible);
  32. }
  33. }
  34. public class IoButton : ToggleButton
  35. {
  36. public static readonly DependencyProperty ONProperty;
  37. static IoButton()
  38. {
  39. ONProperty = DependencyProperty.Register("ON", typeof(bool), typeof(IoButton));
  40. }
  41. public bool ON
  42. {
  43. get { return (bool)GetValue(ONProperty); }
  44. set { SetValue(ONProperty, value); }
  45. }
  46. }
  47. public class BoolBackgroundConverter : IValueConverter
  48. {
  49. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  50. {
  51. bool? ret = (bool?)value;
  52. return ret.HasValue && ret.Value ? "LightBlue" : "Transparent";
  53. }
  54. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  55. {
  56. return null;
  57. }
  58. }
  59. }