|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- 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>
- /// CircularDiagram.xaml 的交互逻辑
- /// </summary>
- public partial class CircularDiagram : UserControl
- {
- public CircularDiagram()
- {
- InitializeComponent();
- this.Loaded += (s, e) => { sData = this.path.Data.ToString(); Refresh(); };
- }
- string sData = string.Empty;
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- (d as CircularDiagram)?.Refresh();
- }
-
- private void Refresh()
- {
- if (Value <= 0)
- {
- this.path.Visibility = Visibility.Collapsed;
- this.tb.Text = "0%";
- }
- else
- {
- var datas = sData.Split('z');
- if (int.TryParse(Math.Round(Value * 0.36f).ToString(), out int temp))
- {
- if (temp >= 0 && temp <= datas.Length - 1)
- {
- StringBuilder sb = new StringBuilder();
- datas[0..temp].ToList()?.ForEach(item =>
- {
- sb.Append($"{item}z");
- });
- var converter = TypeDescriptor.GetConverter(typeof(Geometry));
- this.path.Data = (Geometry)converter.ConvertFrom(sb.ToString());
- }
- }
- this.path.Visibility = Visibility.Visible;
- this.tb.Text = $"{Value}%";
- }
- }
-
- public int Value
- {
- get { return (int)GetValue(ValueProperty); }
- set { SetValue(ValueProperty, value); }
- }
- public static readonly DependencyProperty ValueProperty =
- DependencyProperty.Register("Value", typeof(int), typeof(CircularDiagram),
- new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
-
-
-
- }
- }
|