in the design interface, sometimes encountered progress bar, this time how WPF design custom circle progress bar, directly on the code:

201842517612

 / / / < summary> / / / / progress bar / / / / / < /summary> public partial class ProgressBarControl: UserControl {/ / / / / / / / / / / / / / / / / / public partial class ProgressBarControl. Private DispatcherTimer animationTimer; private ProgressBarDataModel _dataModel; private int index = 0; #region construction method and load / / / < summary> / / / / / / / / / / / / {};} / / / / < summary> / / / / / / / / / / / / < /summary> / / / < param name= "sender" > < /param> / / / / < CherPriority.ContextIdle, Dispatcher); / / / / / / specified time interval animationTimer.Interval = new TimeSpan (0, 0, 0, 0, TimeSpan); if (EllipseCount < 1) {EllipseCount = 12;} for Add (New Ellipse ());} var dataModel = new ProgressBarDataModel () {CanvasSize = CanvasSize, EclipseSize = EllipseSize}; _dataModel = {};} Get or set circle number / / / / / default 12 / / / < /summary> public double EllipseCount {get {return (double) GetValue (EllipseCountProperty);} set {SetValue (})}}} = DependencyProperty.Register ("EllipseCount", typeof (double), typeof (ProgressBarControl), new FrameworkPropertyMetadata (10, FrameworkPropertyMetadataOptions.AffectsRender)); / / / / < summary> / / / / / / / / / / / / / / / / / < Ouble EllipseSize {get {return (double) GetValue (EllipseSizeProperty);} set {SetValue (EllipseSizeProperty, value);} public. L), new FrameworkPropertyMetadata (10, FrameworkPropertyMetadataOptions.AffectsRender)); / / / < summary> / / / / get or set the panel size / / / / / default 80 / / / < /summary> public double CanvasSize {get {{};} Set {SetValue (CanvasSizeProperty, value);}} public static readonly DependencyProperty CanvasSizeProperty = DependencyProperty.Register ("CanvasSize"). ); / / / / < summary> / / / / / / get or set each rotation angle / / / / default 10 / / / / / / / < /summary> public double StepAngle {get {{return (double) GetValue (StepAngleProperty);} YProperty StepAngleProperty = DependencyProperty.Register ("StepAngle", typeof (double), typeof (ProgressBarControl), new FrameworkPropertyMetadata (10, FrameworkPropertyMetadataOptions.AffectsRender)); / / / < / / / / / / get or set each rotation interval time (millisecond) / / / / / / / / / / / / / / / / / / / / < /summary> public int TimeSpan {get {return (int) GetValue (TimeSpanProperty);} set {SetValue}}}} Peof (int), typeof (ProgressBarControl), new FrameworkPropertyMetadata (100, FrameworkPropertyMetadataOptions.AffectsRender)); #endregion #region method / / / < summary> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <. Lt; param name= "e" > < /param> private void HandleLoaded (object sender) {/ / / / / / / set setting circle position and rotation angle; provide additional properties for communication with the designer. If (! DesignerProperties.GetIsInDesignMode (this)) {if (this.Visibility = = System.Windows.Visibility.Visible) {/ / / / / / / / / / / / / / / / / / / / / / / / / / / = / / / / / / / / / / / / / / / this) occurs when the timer interval is more than. AnimationTimer.Tick + = HandleAnimationTick; animationTimer.Start ();}}} / / / / / / / / < summary> / / / / / / / / / / / / / / / / < /summary> private void SetEclipsePosition (ProgressBarDataModel dataModel) {/ / round perimeter is = = = = / / / round perimeter is = Pi * D or C=2* PI *r (where D is the diameter of the circle, R is the radius of the circle) double R =dataModel.R; VAR children=ProgressBarCanvas.Children; int count = =; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / = = = 0; Foreach (VaR element in children) {var ellipse = element as Ellipse; / / / / transparency var opacity = {] Tep*index) *r; ellipse.SetValue (Canvas.LeftProperty, left); double top = R - Math.Cos (step*index) *r; ellipse.SetValue,} / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Canvas.LeftProperty Der "> < /param> / / / < param name=" e "> < /param> private delegate {} {};} / / / / / / / / / / more than the timer. It happens at intervals. / / / / < /summary> / / / < param name= "sender" > < /param> / / / < param name=; {/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / < Gion}

data class Model class:

 / / / / / / < summary> / / / / progress bar Model class / / / < /summary> {double length = Convert.ToDouble (CanvasSize) - Convert.ToDouble (EclipseSize); return length;}} public double EclipseLeftLength {get {get {} = {} / 2;}}} E R {get {double length = (Convert.ToDouble (CanvasSize) - Convert.ToDouble (EclipseSize)) / 2; return length;}}}

, "100" "10" "10" "36" MeSpan= "60" />,

above is the whole content of this article, I hope it will help everyone learn, and I hope you will support the script home more.

This paper fixed link:http://www.script-home.com/wpf-implementation-of-the-loop-progress-bar-effect.html | Script Home | +Copy Link

Article reprint please specify:WPF implementation of the loop progress bar effect | Script Home

You may also be interested in these articles!