WPF loading spinner

后端 未结 14 865
我寻月下人不归
我寻月下人不归 2020-12-02 05:30

The goal is to display the information that the application is working. So I\'m looking for an intelligent implementation sample of a loading spinner using WPF / MVVM.

14条回答
  •  被撕碎了的回忆
    2020-12-02 06:04

    The approach is to use geometry with animations applied. Add the required geometry to the Path and animate its RotateTransform from 0-360°.

    My spinner support two types of spinners:

    1. Circles :
    2. Rings :

    And the central logic looks like:

    if(spinner.SpinnerType == SpinnerType.Ring)
    {
     double innerRad = spinner.Radius - spinner.ItemRadius;
     Point center = new Point(0, 0);
     grp.Children.Add(new EllipseGeometry( center, spinner.Radius, spinner.Radius));
     grp.Children.Add(new EllipseGeometry(center, innerRad, innerRad));                
     return;
    }
    var points = GetPointsOnCircle( spinner.Diameter/ 2);
    double r = spinner.ItemRadius;
    foreach (var point in points)
    {
     grp.Children.Add(new EllipseGeometry(point, r, r));
     r -= spinner.ContinuousSizeReduction;
    }
    

    Usage is as simple as follows:

    Here is the source code!

提交回复
热议问题