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 AIK.Views.MenuPages.CommonPage { /// /// PercentProgressBar.xaml 的交互逻辑 /// public partial class PercentProgressBar : UserControl { public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(PercentProgressBar), new PropertyMetadata(0.0, OnValueChanged)); public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(PercentProgressBar), new PropertyMetadata(100.0, OnValueChanged)); public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); } public double Maximum { get => (double)GetValue(MaximumProperty); set => SetValue(MaximumProperty, value); } public new Brush Foreground { get => (Brush)GetValue(ForegroundProperty); set => SetValue(ForegroundProperty, value); } public new Brush Background { get => (Brush)GetValue(BackgroundProperty); set => SetValue(BackgroundProperty, value); } public PercentProgressBar() { InitializeComponent(); } private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is PercentProgressBar bar) bar.UpdateIndicator(); } private void UpdateIndicator() { if (Maximum <= 0 || RootGrid.ActualWidth <= 0) return; var percent = Value / Maximum; Indicator.Width = RootGrid.ActualWidth * percent; PercentText.Text = $"{percent * 100:F0}%"; } protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { base.OnRenderSizeChanged(sizeInfo); UpdateIndicator(); } } }