1 #region Methods
2
3
4
5 /// <summary>
6 /// 加载完毕事件
7 /// </summary>
8 /// <param name="sender"></param>
9 /// <param name="e"></param>
10 private void WinViewLoaded(object sender, RoutedEventArgs e)
11 {
12 InitializateData();
13 }
14
15 /// <summary>
16 /// 初始化数据
17 /// </summary>
18 private void InitializateData()
19 {
20 if (!Width.HasValue)
21 {
22 Width = 10;
23 }
24 if (!Height.HasValue)
25 {
26 Height = 10;
27 }
28 if (!EllipseCount.HasValue)
29 {
30 EllipseCount = 10;
31 }
32 if (!WaitTimeSpan.HasValue)
33 {
34 WaitTimeSpan = 0.3;
35 }
36 if (!Space.HasValue)
37 {
38 Space = 10;
39 }
40 if (!this.Duration.HasValue)
41 {
42 this.Duration = 0.5;
43 }
44
45 Ellipses = new List<AnimationObject>();
46 TopGrid.Children.Clear();
47 for (int i = 0; i < EllipseCount; i++)
48 {
49 Ellipses.Add(SetEllipse(i));
50 }
51 }
52
53 /// <summary>
54 /// 设置圆点
55 /// </summary>
56 /// <param name="_index"></param>
57 /// <returns></returns>
58 private AnimationObject SetEllipse(int _index)
59 {
60 //绘制一个椭圆
61 Ellipse e = new Ellipse();
62
63 e.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
64 e.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
65 e.Width = Width.Value;
66 e.Height = Height.Value;
67 e.Fill = Fill;
68 e.Stroke = Stroke;
69 e.StrokeThickness = 2;
70 TransformGroup tg = new TransformGroup();
71 e.RenderTransform = tg;
72 TranslateTransform tt = new TranslateTransform();
73 tg.Children.Add(tt);
74 DoubleAnimation da = new DoubleAnimation();
75 da.Name = "DA" + _index.ToString();
76 da.From = 0;
77 da.To = TopGrid.ActualWidth / 2 + (EllipseCount * Space) / 2 - _index * Space;
78 da.Duration = new Duration(TimeSpan.FromSeconds(this.Duration.Value));
79 da.BeginTime = TimeSpan.FromSeconds(_index * WaitTimeSpan.Value);
80 da.Completed += (s, x) =>
81 {
82 DoubleAnimation thisDa = (s as AnimationClock).Timeline as DoubleAnimation;
83 int DaIndex = int.Parse(thisDa.Name.Replace("DA", ""));
84 DoubleAnimation da2 = new DoubleAnimation();
85 da2.From = thisDa.To;
86 da2.BeginTime = thisDa.BeginTime.Value.Add(TimeSpan.FromSeconds((EllipseCount.Value - 1) * WaitTimeSpan.Value - DaIndex * WaitTimeSpan.Value));
87 da2.To = TopGrid.ActualWidth + Space * EllipseCount - Space - DaIndex * Space;
88 da2.Duration = new Duration(TimeSpan.FromSeconds(this.Duration.Value));
89 if (_index == EllipseCount - 1) //最后一个点二阶段的动画都已结束
90 {
91 da2.Completed += (ss, ee) =>
92 {
93 if (IsBusy) BeginAnimation();
94 else IsWorking = false;
95 };
96 }
97 tt.BeginAnimation(TranslateTransform.XProperty, da2);
98 };
99 TopGrid.Children.Add(e);
100
101 return new AnimationObject() { DoubleAnimation = da,TranslateTransform = tt };
102 }
103
104 /// <summary>
105 /// 开始变动
106 /// </summary>
107 private void BeginAnimation()
108 {
109 IsWorking = true;
110 foreach (var ell in Ellipses)
111 {
112 ell.TranslateTransform.BeginAnimation(TranslateTransform.XProperty, ell.DoubleAnimation);
113 }
114 }
115
116 #endregion