SignalLight.xaml.cs 1.6 KB

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