LED.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. namespace MECF.Framework.UI.Client.CenterViews.Controls
  8. {
  9. public partial class LED : UserControl
  10. {
  11. // Using a DependencyProperty as the backing store for On. This enables animation, styling, binding, etc...
  12. public static readonly DependencyProperty OnProperty =
  13. DependencyProperty.Register("On", typeof(bool), typeof(LED), new PropertyMetadata(false));
  14. // Using a DependencyProperty as the backing store for IsRed. This enables animation, styling, binding, etc...
  15. public static readonly DependencyProperty IsRedProperty =
  16. DependencyProperty.Register("IsRed", typeof(bool), typeof(LED), new PropertyMetadata(false));
  17. public LED()
  18. {
  19. InitializeComponent();
  20. root.DataContext = this;
  21. }
  22. public bool On
  23. {
  24. get => (bool) GetValue(OnProperty);
  25. set => SetValue(OnProperty, value);
  26. }
  27. public bool IsRed
  28. {
  29. get => (bool) GetValue(IsRedProperty);
  30. set => SetValue(IsRedProperty, value);
  31. }
  32. }
  33. public class LedConverter : IMultiValueConverter
  34. {
  35. static Brush GreenBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF07FF07"));
  36. static Brush GrayBrush = new SolidColorBrush(Colors.LightGray);
  37. static Brush RedBrush = new SolidColorBrush(Colors.Red);
  38. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  39. {
  40. var value = (bool)values[0];
  41. var red = (bool)values[1];
  42. return value ? red ? RedBrush : GreenBrush : GrayBrush;
  43. }
  44. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. }
  49. }