|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- /// <summary>
- /// Bottle.xaml 的交互逻辑
- /// </summary>
- public partial class Bottle : UserControl
- {
- public Bottle()
- {
- InitializeComponent();
- this.SizeChanged += Bottle_SizeChanged;
- }
-
- private void Bottle_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- e1.Width = this.Width;
- e1.Height = this.Height * 0.09;
-
- r1.Width = this.Width;
- r1.Height = this.Height * 0.8;
- Canvas.SetTop(r1, e1.Height / 2);
-
- bd.Width = this.Width * 0.6;
- bd.Height = this.Height * 0.06;
- Canvas.SetLeft(bd, (this.Width - bd.Width) / 2);
- Canvas.SetBottom(bd, 0);
-
- e2.Width = this.Width;
- e2.Height = this.Height * 0.09;
- Canvas.SetTop(e2, r1.Height);
- Canvas.SetLeft(e2, 0);
-
-
- PathGeometry geometry = new PathGeometry();
- PathFigure pathFigure = new PathFigure();
- pathFigure.StartPoint = new Point(0, r1.Height + (e1.Height / 2));
- pathFigure.Segments.Add(new LineSegment(new Point(Canvas.GetLeft(bd), this.Height - bd.Height), true));
- pathFigure.Segments.Add(new LineSegment(new Point(Canvas.GetLeft(bd) + bd.Width, this.Height - bd.Height), true));
- pathFigure.Segments.Add(new LineSegment(new Point(this.Width, r1.Height + (e1.Height / 2)), true));
- pathFigure.Segments.Add(new LineSegment(new Point(0, r1.Height + (e1.Height / 2)), true));
- geometry.Figures.Add(pathFigure);
- this.pa.Data = geometry;
- Canvas.SetTop(this.pa, r1.Height + (e1.Height / 2));
- Canvas.SetLeft(this.pa, 0);
-
- refile.Width = this.Width;
- Canvas.SetBottom(refile, this.Height - r1.Height - (e1.Height / 2));
- Refresh();
- }
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as Bottle)?.Refresh();
- }
-
- private void Refresh()
- {
- double height = LinearConvert(CurrentValue, r1.Height, 0F, 100F, 0F);
- refile.Height = height;
- }
-
- private double LinearConvert(double IntputValue, double OSH, double OSL, double ISH, double ISL)
- {
- if (IntputValue >= ISH) return OSH;
- if (IntputValue <= ISL) return OSL;
- return (IntputValue - ISL) * (OSH - OSL) / (ISH - ISL) + OSL;
- }
-
- public double CurrentValue
- {
- get { return (double)GetValue(CurrentValueProperty); }
- set { SetValue(CurrentValueProperty, value); }
- }
- public static readonly DependencyProperty CurrentValueProperty =
- DependencyProperty.Register("CurrentValue", typeof(double), typeof(Bottle),
- new PropertyMetadata(0.0, new PropertyChangedCallback(OnPropertyChanged)));
-
- }
- }
|