SignalLight.xaml.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace MaintainModule.Controls;
  16. /// <summary>
  17. /// Interaction logic for SignalLight.xaml
  18. /// </summary>
  19. public partial class SignalLight : UserControl
  20. {
  21. public SignalLight()
  22. {
  23. InitializeComponent();
  24. }
  25. public bool IsOn
  26. {
  27. get { return (bool)GetValue(IsOnProperty); }
  28. set { SetValue(IsOnProperty, value); }
  29. }
  30. // Using a DependencyProperty as the backing store for IsOn. This enables animation, styling, binding, etc...
  31. public static readonly DependencyProperty IsOnProperty =
  32. DependencyProperty.Register(nameof(IsOn), typeof(bool), typeof(SignalLight), new PropertyMetadata(false, PropertyChangedCallback));
  33. static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  34. {
  35. if (d is not SignalLight light)
  36. return;
  37. if (e.NewValue is not bool on)
  38. return;
  39. light.light.Fill = on ?
  40. (SolidColorBrush)Application.Current.Resources["NiceGreen"] :
  41. (SolidColorBrush)Application.Current.Resources["LightDisableColor"];
  42. }
  43. }