views:

252

answers:

1

Hi,

I've got a KeyFrame Animation storyboard and a separate rotation transformation in my Window.Resources.

The rotation transformation works as I can alter the angle and see the content rotate. I know the storyboard is being called, because it took me a few goes to get the PropertyPath right after I clicked on the button.

However now it does nothing - no error, but no rotation either!

Can anyone help please?

Thanks,

Andy

<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>
+1  A: 

Hi Andy,

The problem is in Storyboard.Target="{Binding TemplatedParent}". Give a name to Viewport2DVisual3D control: <Viewport2DVisual3D x:Name="vp" .../>, and set Storyboard.TargetName="vp" instead of what you have...

Cheers

Anvaka
nice one, thanks very much
Andy Clarke