2009-12-14 34 views
1

我的Window.Resources中有一个KeyFrame动画故事板和一个单独的旋转转换。WPF - KeyFrame动画不起作用

旋转变换的工作原理是我可以改变角度并查看内容旋转。我知道故事板正在被调用,因为在点击按钮后,我花了几次去获取PropertyPath。

但是现在它什么都不做 - 没有错误,但没有旋转!

任何人都可以帮忙吗?

感谢,

安迪

<Window 
     x:Class="WpfApplication1.Window1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Height="300" Width="400"> 
    <Window.Resources> 

     <Storyboard x:Key="myStoryboard"> 
      <Rotation3DAnimationUsingKeyFrames 
         Storyboard.Target="{Binding TemplatedParent}"  
         Storyboard.TargetProperty="(Viewport2DVisual3D.Transform).(RotateTransform3D.Rotation)" > 
       <Rotation3DAnimationUsingKeyFrames.KeyFrames> 
        <LinearRotation3DKeyFrame KeyTime="0:0:1"> 
         <LinearRotation3DKeyFrame.Value> 
          <AxisAngleRotation3D Axis="0,1,0" Angle="0" /> 
         </LinearRotation3DKeyFrame.Value> 
        </LinearRotation3DKeyFrame> 
       </Rotation3DAnimationUsingKeyFrames.KeyFrames> 
      </Rotation3DAnimationUsingKeyFrames> 
     </Storyboard> 

     <RotateTransform3D x:Key="myRotateTransform3D" > 
      <RotateTransform3D.Rotation> 
       <AxisAngleRotation3D Axis="0,1,0" Angle="30" /> 
      </RotateTransform3D.Rotation> 
     </RotateTransform3D> 

     <!-- Front, left square --> 
     <MeshGeometry3D 
        x:Key="squareMeshFront" 
        Positions="-1,-1,1 1,-1,1 1,1,1 -1,1,1" 
        TriangleIndices="0 1 2 0 2 3" 
        TextureCoordinates="0,1 1,1 1,0 0,0" /> 
     <!-- Bottom --> 
     <MeshGeometry3D 
        x:Key="squareMeshBottom" 
        Positions="-1,-1,1 1,-1,1 1,-1,-1 1,1,-1" 
        TriangleIndices="0 1 2 0 2 3" 
        TextureCoordinates="0,1 1,1 1,0 0,0" /> 


     <DiffuseMaterial x:Key="visualHostMaterial" Brush="White" Viewport2DVisual3D.IsVisualHostMaterial="True" /> 
    </Window.Resources> 

    <Viewport3D> 


     <Viewport3D.Camera> 
      <PerspectiveCamera Position="0,0,9" LookDirection="0,0,-1" /> 
     </Viewport3D.Camera> 

     <Viewport2DVisual3D Material="{StaticResource visualHostMaterial}" Geometry="{StaticResource squareMeshFront}" Transform="{StaticResource myRotateTransform3D}" > 

      <StackPanel Background="Blue" Width="120" Height="80"> 
       <Button Height="30" Margin="20"> 
        <Button.Content>Click Me</Button.Content> 
        <Button.Triggers> 
         <EventTrigger RoutedEvent="Button.Click"> 
          <EventTrigger.Actions> 
           <BeginStoryboard Storyboard="{StaticResource myStoryboard}" > 
           </BeginStoryboard> 
          </EventTrigger.Actions> 
         </EventTrigger> 
        </Button.Triggers> 
       </Button> 
      </StackPanel> 
     </Viewport2DVisual3D> 

     <ModelVisual3D> 
      <ModelVisual3D.Content> 
       <AmbientLight Color="White" /> 
      </ModelVisual3D.Content> 
     </ModelVisual3D> 
    </Viewport3D> 
</Window> 

回答

2

问题出在Storyboard.Target="{Binding TemplatedParent}"。提供一个名称Viewport2DVisual3D控制:<Viewport2DVisual3D x:Name="vp" .../>,并设置Storyboard.TargetName="vp",而不是你有什么...

干杯

+0

不错的一个,非常感谢 – 2009-12-14 17:44:36