CommonValveControl.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace Venus_Themes.CustomControls
  9. {
  10. public class CommonValveControl : Control
  11. {
  12. public CommonValveControl()
  13. {
  14. //this.MouseDoubleClick += CommonValveControl_MouseDoubleClick;
  15. }
  16. static CommonValveControl()
  17. {
  18. DefaultStyleKeyProperty.OverrideMetadata(typeof(CommonValveControl), new FrameworkPropertyMetadata(typeof(CommonValveControl)));
  19. }
  20. //private void CommonValveControl_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  21. //{
  22. // Status = !Status;
  23. //}
  24. public override void OnApplyTemplate()
  25. {
  26. var devBtn = GetTemplateChild("mainBody") as Grid;
  27. devBtn.MouseLeftButtonDown += DevBtn_Click;
  28. base.OnApplyTemplate();
  29. }
  30. private void DevBtn_Click(object sender, RoutedEventArgs e)
  31. {
  32. Status = !Status;
  33. }
  34. public bool Status
  35. {
  36. get => (bool)GetValue(StatusProperty);
  37. set => SetValue(StatusProperty, value);
  38. }
  39. public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(
  40. "Status",
  41. typeof(bool),
  42. typeof(CommonValveControl));
  43. public Orientation ValveOrientation
  44. {
  45. get => (Orientation)GetValue(CommonValveOrientationProperty);
  46. set => SetValue(CommonValveOrientationProperty, value);
  47. }
  48. public static readonly DependencyProperty CommonValveOrientationProperty = DependencyProperty.Register(
  49. "ValveOrientation",
  50. typeof(Orientation),
  51. typeof(CommonValveControl));
  52. }
  53. }