using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace BPA.UIControl { /// /// 加载中 /// [TemplatePart(Name = MessageTextPartName, Type = typeof(TextBlock))] public class Loading : ContentControl { /// /// 消息文本名称 /// public const string MessageTextPartName = "Path_MessageText"; static Loading() { DefaultStyleKeyProperty.OverrideMetadata(typeof(Loading), new FrameworkPropertyMetadata(typeof(Loading))); } /// public override void OnApplyTemplate() { base.OnApplyTemplate(); } /// /// 边框厚度 /// public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register( "StrokeThickness", typeof(double), typeof(Loading), new PropertyMetadata(default(double))); /// /// 边框厚度 /// public double StrokeThickness { get { return (double)GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, value); } } /// /// 虚线和间隙的值的集合 /// public static readonly DependencyProperty StrokeDashArrayProperty = DependencyProperty.Register( "StrokeDashArray", typeof(DoubleCollection), typeof(Loading), new PropertyMetadata(default(DoubleCollection))); /// /// 虚线和间隙的值的集合 /// public DoubleCollection StrokeDashArray { get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); } set { SetValue(StrokeDashArrayProperty, value); } } /// /// 聚焦颜色 /// public static readonly DependencyProperty FocusedBrushProperty = DependencyProperty.RegisterAttached( "FocusedBrush", typeof(Brush), typeof(Loading), new PropertyMetadata(default(Brush))); /// /// 聚焦颜色 /// public Brush FocusedBrush { get { return (Brush)GetValue(FocusedBrushProperty); } set { SetValue(FocusedBrushProperty, value); } } /// /// 进度 /// public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register( "Progress", typeof(double), typeof(Loading), new PropertyMetadata(default(double), OnProgressChanged)); /// /// 进度 /// public double Progress { get { return (double)GetValue(ProgressProperty); } set { SetValue(ProgressProperty, value); } } private static void OnProgressChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var loading = d as Loading; loading.StrokeDashArray = new DoubleCollection(new List { (loading.Diameter - loading.StrokeThickness) * Math.PI / loading.StrokeThickness * loading.Progress, double.MaxValue }); } /// /// 直径 /// public static readonly DependencyProperty DiameterProperty = DependencyProperty.RegisterAttached( "Diameter", typeof(double), typeof(Loading), new PropertyMetadata(default(double))); /// /// 直径 /// public double Diameter { get { return (double)GetValue(DiameterProperty); } set { SetValue(DiameterProperty, value); } } } }