这里我们先看例程源码:

 1 <Window
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication1.MainWindow"
 5         Title="MainWindow" Height="573.575" Width="611">
 6     <Grid>
 7         <DockPanel>
 8             <Viewport3D Name="myViewport">
 9                 <Viewport3D.Camera>
10                     <PerspectiveCamera FarPlaneDistance="20" LookDirection="5,-2,-3" UpDirection="0,1,0" NearPlaneDistance="0" Position="-5,2,3" FieldOfView="45" />
11                 </Viewport3D.Camera>
12 
13                 <ModelVisual3D x:Name="topModelVisual3D">
14                     <ModelVisual3D.Children>
15                         <ModelVisual3D>
16                             <ModelVisual3D.Content>
17                                 <DirectionalLight Color="White" Direction="-3,-4,-5" />
18                             </ModelVisual3D.Content>
19                         </ModelVisual3D>
20                         <ModelVisual3D>
21                             <ModelVisual3D.Content>
22                                 <GeometryModel3D Geometry="{StaticResource myTeapot}">
23                                     <GeometryModel3D.Material>
24                                         <DiffuseMaterial>
25                                             <DiffuseMaterial.Brush>
26                                                 <SolidColorBrush Color="White" Opacity="1.0" />
27                                             </DiffuseMaterial.Brush>
28                                         </DiffuseMaterial>
29                                     </GeometryModel3D.Material>
30                                     <GeometryModel3D.Transform>
31                                         <RotateTransform3D>
32                                             <RotateTransform3D.Rotation>
33                                                 <AxisAngleRotation3D x:Name="myAngleRotation" Axis="0,10,0" Angle="1" />
34                                             </RotateTransform3D.Rotation>
35                                         </RotateTransform3D>
36                                     </GeometryModel3D.Transform>
37                                 </GeometryModel3D>
38                             </ModelVisual3D.Content>
39                         </ModelVisual3D>
40                     </ModelVisual3D.Children>
41                 </ModelVisual3D>
42                 
43                 <Viewport3D.Triggers>
44                     <EventTrigger RoutedEvent="Viewport3D.Loaded">
45                         <BeginStoryboard>
46                             <Storyboard>
47                                 <DoubleAnimation 
48                                     Storyboard.TargetName="myAngleRotation"
49                                     Storyboard.TargetProperty="Angle"
50                                     From="0" To="360" Duration="0:0:5"
51                                     RepeatBehavior="Forever" />
52                             </Storyboard>
53                         </BeginStoryboard>
54                     </EventTrigger>
55                 </Viewport3D.Triggers>
56                 
57             </Viewport3D>
58         </DockPanel>
59     </Grid>
60 </Window>
XAML

相关文章:

  • 2021-08-28
  • 2021-10-28
  • 2021-07-31
  • 2022-01-22
  • 2022-12-23
  • 2021-07-08
猜你喜欢
  • 2021-09-08
  • 2021-11-07
  • 2022-12-23
  • 2022-01-17
  • 2021-10-26
  • 2021-09-27
  • 2021-12-08
相关资源
相似解决方案