ValueBar.xaml.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 SummaryModule.Controls;
  16. /// <summary>
  17. /// Interaction logic for ValueBar.xaml
  18. /// </summary>
  19. public partial class ValueBar : UserControl
  20. {
  21. public ValueBar()
  22. {
  23. InitializeComponent();
  24. }
  25. public float MaxValue
  26. {
  27. get { return (float)GetValue(MaxValueProperty); }
  28. set { SetValue(MaxValueProperty, value); }
  29. }
  30. public static readonly DependencyProperty MaxValueProperty =
  31. DependencyProperty.Register(nameof(MaxValue), typeof(float), typeof(ValueBar), new PropertyMetadata(100f));
  32. public float Value
  33. {
  34. get { return (float)GetValue(ValueProperty); }
  35. set { SetValue(ValueProperty, value); }
  36. }
  37. public static readonly DependencyProperty ValueProperty =
  38. DependencyProperty.Register(nameof(Value), typeof(float), typeof(ValueBar), new PropertyMetadata(0f, PropertyChangedCallback));
  39. static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  40. {
  41. if (d is not ValueBar valueBar)
  42. return;
  43. if (e.NewValue is not float value)
  44. return;
  45. switch (value)
  46. {
  47. case >= 0:
  48. valueBar.pos.Value = value;
  49. valueBar.neg.Value = 0;
  50. break;
  51. case < 0:
  52. valueBar.pos.Value = 0;
  53. valueBar.neg.Value = Math.Abs(value);
  54. break;
  55. }
  56. }
  57. }