终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

95 řádky
3.3 KiB

  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 BPASmartClient.CustomResource.UserControls
  16. {
  17. /// <summary>
  18. /// Bottle.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class Bottle : UserControl
  21. {
  22. public Bottle()
  23. {
  24. InitializeComponent();
  25. this.SizeChanged += Bottle_SizeChanged;
  26. }
  27. private void Bottle_SizeChanged(object sender, SizeChangedEventArgs e)
  28. {
  29. e1.Width = this.Width;
  30. e1.Height = this.Height * 0.09;
  31. r1.Width = this.Width;
  32. r1.Height = this.Height * 0.8;
  33. Canvas.SetTop(r1, e1.Height / 2);
  34. bd.Width = this.Width * 0.6;
  35. bd.Height = this.Height * 0.06;
  36. Canvas.SetLeft(bd, (this.Width - bd.Width) / 2);
  37. Canvas.SetBottom(bd, 0);
  38. e2.Width = this.Width;
  39. e2.Height = this.Height * 0.09;
  40. Canvas.SetTop(e2, r1.Height);
  41. Canvas.SetLeft(e2, 0);
  42. PathGeometry geometry = new PathGeometry();
  43. PathFigure pathFigure = new PathFigure();
  44. pathFigure.StartPoint = new Point(0, r1.Height + (e1.Height / 2));
  45. pathFigure.Segments.Add(new LineSegment(new Point(Canvas.GetLeft(bd), this.Height - bd.Height), true));
  46. pathFigure.Segments.Add(new LineSegment(new Point(Canvas.GetLeft(bd) + bd.Width, this.Height - bd.Height), true));
  47. pathFigure.Segments.Add(new LineSegment(new Point(this.Width, r1.Height + (e1.Height / 2)), true));
  48. pathFigure.Segments.Add(new LineSegment(new Point(0, r1.Height + (e1.Height / 2)), true));
  49. geometry.Figures.Add(pathFigure);
  50. this.pa.Data = geometry;
  51. Canvas.SetTop(this.pa, r1.Height + (e1.Height / 2));
  52. Canvas.SetLeft(this.pa, 0);
  53. refile.Width = this.Width;
  54. Canvas.SetBottom(refile, this.Height - r1.Height - (e1.Height / 2));
  55. Refresh();
  56. }
  57. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  58. {
  59. (d as Bottle)?.Refresh();
  60. }
  61. private void Refresh()
  62. {
  63. double height = LinearConvert(CurrentValue, r1.Height, 0F, 100F, 0F);
  64. refile.Height = height;
  65. }
  66. private double LinearConvert(double IntputValue, double OSH, double OSL, double ISH, double ISL)
  67. {
  68. if (IntputValue >= ISH) return OSH;
  69. if (IntputValue <= ISL) return OSL;
  70. return (IntputValue - ISL) * (OSH - OSL) / (ISH - ISL) + OSL;
  71. }
  72. public double CurrentValue
  73. {
  74. get { return (double)GetValue(CurrentValueProperty); }
  75. set { SetValue(CurrentValueProperty, value); }
  76. }
  77. public static readonly DependencyProperty CurrentValueProperty =
  78. DependencyProperty.Register("CurrentValue", typeof(double), typeof(Bottle),
  79. new PropertyMetadata(0.0, new PropertyChangedCallback(OnPropertyChanged)));
  80. }
  81. }