|
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- 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.MilkWithTea.Control
- {
- /// <summary>
- /// CircularProgressBar.xaml 的交互逻辑
- /// </summary>
- public partial class CircularProgressBar : UserControl
- {
- public CircularProgressBar()
- {
- InitializeComponent();
- UpdateValue(Percent * 3.6);
- }
- public double Percent
- {
- get { return (double)GetValue(PercentProperty); }
- set
- {
- SetValue(PercentProperty, value);
- UpdateValue(Percent * 3.6);
- }
-
- }
-
- //public static DependencyProperty PercentProperty => percentProperty;
-
- // Using a DependencyProperty as the backing store for Percent. This enables animation, styling, binding, etc...
- private static readonly DependencyProperty PercentProperty =
- DependencyProperty.Register("Percent", typeof(double), typeof(CircularProgressBar), new PropertyMetadata(default(double), new PropertyChangedCallback(OnPropertyChanged)));
-
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- CircularProgressBar _cycleProgess = d as CircularProgressBar;
- _cycleProgess.UpdateValue(_cycleProgess.Percent * 3.6);
- }
- private void UpdateValue(double angle)
- {
-
- if (angle > 360) return;
- if (angle <= 0) return;
-
- int offset = 5;
- if (angle > 359) angle = 359.8;
- double radius = this.Width / 2 - offset;
- if (radius < 0) return;
- double b = radius * Math.Sin(angle * Math.PI / 180);
- double x = radius + b;
- double y = radius - radius * Math.Cos(angle * Math.PI / 180);
- double startPositionX = radius + offset;
- double startPositionY = offset;
-
- if (angle > 180)
- {
-
- //string Data = string.Format("M {0} 0 A {0} {0} 0 1 1 {1} {2}", radius, Math.Round(x, 2), Math.Round(y, 2));
- string Data = string.Format("M {0} {1} A {2} {2} 0 1 1 {3} {4}", startPositionX, startPositionY, radius, Math.Round(x, 2) + offset, Math.Round(y, 2) + offset);
- this.cyclePath.Data = Geometry.Parse(Data);
- }
- else
- {
-
- //string Data = string.Format("M {0} 0 A {0} {0} 0 0 1 {1} {2}", radius, Math.Round(x,2), Math.Round(y, 2));
-
- string Data = string.Format("M {0} {1} A {2} {2} 0 0 1 {3} {4}", startPositionX, startPositionY, radius, Math.Round(x, 2) + offset, Math.Round(y, 2) + offset);
-
- this.cyclePath.Data = Geometry.Parse(Data);
- }
- }
-
- }
- }
|