SwitchBase.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 SwitchBase : UserControl, IBoostStationPoint
  22. {
  23. public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(SwitchBase));
  24. public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(SwitchBase));
  25. public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
  26. public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
  27. public bool IsTemplete { get; set; }
  28. public string DataTag { get; set; }
  29. public bool IsEditModel { get; set; }
  30. public int Proportion { get; set; }
  31. public string Info { get; set; }
  32. public bool IsNegate { get; set; }
  33. public Action<Control> Clicked { get; set; }
  34. /// <summary>
  35. /// 原始宽
  36. /// </summary>
  37. private double _Width;
  38. /// <summary>
  39. /// 原始高
  40. /// </summary>
  41. private double _Height;
  42. public SwitchBase()
  43. {
  44. InitializeComponent();
  45. _Width = Width;
  46. _Height = Height;
  47. }
  48. private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  49. {
  50. IsSelected = !IsSelected && !IsTemplete && IsEditModel;
  51. Clicked?.Invoke(this);
  52. }
  53. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  54. {
  55. ToZoom();
  56. }
  57. private void ToZoom()
  58. {
  59. this.Width = _Width * (1 + Proportion * 0.1);
  60. this.Height = _Height * (1 + Proportion * 0.1);
  61. }
  62. public void Zoom(int times)
  63. {
  64. Proportion += times;
  65. ToZoom();
  66. }
  67. }
  68. }