首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF - KeyFrame动画不工作

WPF - KeyFrame动画不工作
EN

Stack Overflow用户
提问于 2009-12-14 21:24:06
回答 1查看 949关注 0票数 1

我在我的Window.Resources中有一个KeyFrame动画情节串连板和一个单独的旋转变换。

旋转转换工作,因为我可以改变角度,并看到内容旋转。我知道故事板正在被调用,因为在我点击按钮之后,我花了几次时间才得到PropertyPath。

然而,现在它什么也不做-没有错误,但也没有旋转!

有谁能帮帮忙吗?

谢谢,

安迪

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-14 22:06:43

问题出在Storyboard.Target="{Binding TemplatedParent}"上。为Viewport2DVisual3D控件命名为:<Viewport2DVisual3D x:Name="vp" .../>,并设置Storyboard.TargetName="vp"而不是您已有的...

干杯

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1900905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档