WPF loading spinner

后端 未结 14 861
我寻月下人不归
我寻月下人不归 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:07

    The customized spinner posted by @Menol had a small issue where the spinner would be shifted down and to the right by the size of one dot. I have updated the code so that it compensates for this offset by subtracting by half the dot.

    Here is the updated code:

        private void initialSetup()
        {
            float horizontalCenter = (float)(SpinnerWidth / 2);
            float verticalCenter = (float)(SpinnerHeight / 2);
            float distance = (float)Math.Min(SpinnerHeight, SpinnerWidth) / 2;
            float dotComp = (float)(EllipseSize / 2);
    
            double angleInRadians = 44.8;
            float cosine = (float)Math.Cos(angleInRadians);
            float sine = (float)Math.Sin(angleInRadians);
    
            EllipseN = newPos(left: horizontalCenter - dotComp, top: verticalCenter - distance - dotComp);
            EllipseNE = newPos(left: horizontalCenter + (distance * cosine) - dotComp, top: verticalCenter - (distance * sine) - dotComp);
            EllipseE = newPos(left: horizontalCenter + distance - dotComp, top: verticalCenter - dotComp);
            EllipseSE = newPos(left: horizontalCenter + (distance * cosine) - dotComp, top: verticalCenter + (distance * sine) - dotComp);
            EllipseS = newPos(left: horizontalCenter - dotComp, top: verticalCenter + distance - dotComp);
            EllipseSW = newPos(left: horizontalCenter - (distance * cosine) - dotComp, top: verticalCenter + (distance * sine) - dotComp);
            EllipseW = newPos(left: horizontalCenter - distance - dotComp, top: verticalCenter - dotComp);
            EllipseNW = newPos(left: horizontalCenter - (distance * cosine) - dotComp, top: verticalCenter - (distance * sine) - dotComp);
        }
    

提交回复
热议问题