Switch.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using NEIntelligentControl2.Models.BoostStation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace NEIntelligentControl2.Views.BoostStation
  17. {
  18. /// <summary>
  19. /// 开关
  20. /// </summary>
  21. public partial class Switch : UserControl, IBoostStationPoint
  22. {
  23. public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(Switch));
  24. public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(Switch));
  25. public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
  26. public double Value
  27. {
  28. get => (double)GetValue(ValueProperty);
  29. set
  30. {
  31. double d = value;
  32. if (IsNegate)
  33. {
  34. d = d == 0 ? 1 : 0;
  35. }
  36. SetValue(ValueProperty, d);
  37. }
  38. }
  39. public bool IsTemplete { get; set; }
  40. public string DataTag { get; set; }
  41. public bool IsEditModel { get; set; }
  42. public int Proportion { get; set; }
  43. public string Info { get; set; }
  44. public bool IsNegate { get; set; }
  45. public Action<Control> Clicked { get; set; }
  46. /// <summary>
  47. /// 原始宽
  48. /// </summary>
  49. private double _Width;
  50. /// <summary>
  51. /// 原始高
  52. /// </summary>
  53. private double _Height;
  54. public Switch()
  55. {
  56. Value = -1;
  57. InitializeComponent();
  58. _Width = Width;
  59. _Height = Height;
  60. }
  61. private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  62. {
  63. IsSelected = !IsSelected && !IsTemplete && IsEditModel;
  64. Clicked?.Invoke(this);
  65. }
  66. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  67. {
  68. ToZoom();
  69. }
  70. private void ToZoom()
  71. {
  72. this.Width = _Width * (1 + Proportion * 0.1);
  73. this.Height = _Height * (1 + Proportion * 0.1);
  74. }
  75. public void Zoom(int times)
  76. {
  77. Proportion += times;
  78. ToZoom();
  79. }
  80. }
  81. }