1
public
void
MoveCurrentToNext()
2
{
3
//
向前移动,取Viewport3D的第一个Viewport2DVisual3为当前Viewport2DVisual3D
4
var current
=
this
.Viewport3D.Children[
0
];
5
var child1
=
this
.Viewport3D.Children[
1
];
6
var child2
=
this
.Viewport3D.Children[
2
];
7
var child3
=
this
.Viewport3D.Children[
3
];
8
var child4
=
this
.Viewport3D.Children[
4
];
9
var child5
=
this
.Viewport3D.Children[
5
];
10
11
12
this
.Viewport3D.Children.RemoveAt(
0
);
13
this
.Viewport3D.Children.Insert(
5
, current);
14
15
var translate
=
(current.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
16
17
//
对每个Viewport2DVisual3D元素应用平移动画
18
AnimationVisualElement((current
as
Viewport2DVisual3D).Visual
as
FrameworkElement, .
3
);
19
AnimationVisualElement(translate,
true
,
-
5.0
,
1.5
,
-
20.0
);
20
21
translate
=
(child1.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
22
AnimationVisualElement(translate,
true
, .
0
, .
0
, .
0
);
23
24
translate
=
(child2.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
25
AnimationVisualElement(translate,
true
,
-
1.0
,
1.0
,
-
4.0
);
26
27
translate
=
(child3.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
28
AnimationVisualElement(translate,
true
,
-
2.0
,
1.5
,
-
8.0
);
29
30
translate
=
(child4.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
31
AnimationVisualElement(translate,
true
,
-
3.0
,
1.5
,
-
12.0
);
32
33
translate
=
(child5.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
34
AnimationVisualElement(translate,
true
,
-
4.0
,
1.5
,
-
16.0
);
35
36
}
37
38
public
void
MoveCurrentToPrevious()
39
{
40
//
向后移动,取Viewport3D的最后一个Viewport2DVisual3D当前Viewport2DVisual3D
41
var current
=
this
.Viewport3D.Children[
5
];
42
var child1
=
this
.Viewport3D.Children[
0
];
43
var child2
=
this
.Viewport3D.Children[
1
];
44
var child3
=
this
.Viewport3D.Children[
2
];
45
var child4
=
this
.Viewport3D.Children[
3
];
46
var child5
=
this
.Viewport3D.Children[
4
];
47
48
this
.Viewport3D.Children.RemoveAt(
5
);
49
this
.Viewport3D.Children.Insert(
0
, current);
50
51
var translate
=
(current.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
52
53
AnimationVisualElement(translate,
false
,
0.0
,
0.0
,
0.0
);
55
56
translate
=
(child1.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
57
AnimationVisualElement(translate,
false
,
-
1.0
,
1.0
,
-
4.0
);
58
59
translate
=
(child2.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
60
AnimationVisualElement(translate,
false
,
-
2.0
,
1.5
,
-
8.0
);
61
62
translate
=
(child3.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
63
AnimationVisualElement(translate,
false
,
-
3.0
,
1.5
,
-
12.0
);
64
65
translate
=
(child4.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
66
AnimationVisualElement(translate,
false
,
-
4.0
,
1.5
,
-
16.0
);
67
68
translate
=
(child5.Transform
as
Transform3DGroup).Children[
1
]
as
TranslateTransform3D;
69
AnimationVisualElement(translate,
false
,
-
5.0
,
1.5
,
-
20.0
);
70
}
71
private
void
AnimationVisualElement(FrameworkElement element,
double
duration)
72
{
73
if
(element
==
null
)
74
return
;
75
//
对Visual元素的Visibility应用动画
76
ObjectAnimationUsingKeyFrames objectAnimation
=
new
ObjectAnimationUsingKeyFrames();
77
objectAnimation.KeyFrames.Add(
new
DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromPercent(.
0
)));
78
objectAnimation.KeyFrames.Add(
new
DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromPercent(
1
)));
79
objectAnimation.Duration
=
TimeSpan.FromSeconds(duration);
80
objectAnimation.FillBehavior
=
FillBehavior.Stop;
81
element.BeginAnimation(FrameworkElement.VisibilityProperty, objectAnimation);
82
83
}
84
private
void
AnimationVisualElement(TranslateTransform3D translate,
bool
forward,
double
targetX,
double
targetY,
double
targetZ)
85
{
86
Duration duration
=
new
Duration(TimeSpan.FromSeconds(.
4
));
87
//
对TranslateTransform3D的X偏移量应用动画
88
DoubleAnimation animationX
=
new
DoubleAnimation();
89
animationX.To
=
targetX;
90
animationX.Duration
=
duration;
91
animationX.AccelerationRatio
=
forward
?
0
:
1
;
92
animationX.DecelerationRatio
=
forward
?
1
:
0
;
93
translate.BeginAnimation(TranslateTransform3D.OffsetXProperty, animationX);
94
//
对TranslateTransform3D的Y偏移量应用动画
95
DoubleAnimation animationY
=
new
DoubleAnimation();
96
animationX.To
=
targetY;
97
animationX.AccelerationRatio
=
forward
?
0.7
:
0.3
;
98
animationX.DecelerationRatio
=
forward
?
0.3
:
0.7
;
99
animationX.Duration
=
duration;
100
translate.BeginAnimation(TranslateTransform3D.OffsetYProperty, animationX);
101
//
对TranslateTransform3D的Z偏移量应用动画
102
DoubleAnimation animationZ
=
new
DoubleAnimation();
103
animationZ.To
=
targetZ;
104
animationZ.AccelerationRatio
=
forward
?
0.3
:
0.7
;
105
animationZ.DecelerationRatio
=
forward
?
0.7
:
0.3
;
106
animationZ.Duration
=
duration;
107
translate.BeginAnimation(TranslateTransform3D.OffsetZProperty, animationZ);
108
}