WPF PropertyPath问题 - 无法解析属性路径中的所有属性引用

时间:2009-12-08 13:22:55

标签: wpf storyboard

我正在努力让PropertyPath工作 - 我在Window资源中有一个转换,我试图通过一个StoryBoard来影响 - 也在Window Resources ...

继承我正在使用的财产路径...

(Viewport2DVisual3D.Transform).(Transform3DGroup)[0].(RotateTransform3D).(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)
编辑:感谢Anurags的建议,我有点进一步......     (Viewport2DVisual3D.Transform)。(Transform3DGroup.Children)[0]。(RotateTransform3D.Rotation)。(AxisAngleRotation3D.Angle)

但是现在它出错了“Rotation属性没有指向DependencyProperty”

有人可以让我回到正轨吗?

完整的代码......

<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="300">
    <Window.Resources>

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

          <Storyboard x:Key="MyStoryboard">
        <DoubleAnimation
       Storyboard.Target="{Binding TemplatedParent}"     
       Storyboard.TargetProperty="(Viewport2DVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"
       From="0.0" To="360" Duration="0:0:1" />
    </Storyboard>

        <MeshGeometry3D
            x:Key="squareMeshFrontLeft"
            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,10" LookDirection="0,0,-1" />
        </Viewport3D.Camera>
        <Viewport2DVisual3D Material="{StaticResource visualHostMaterial}" Geometry="{StaticResource squareMeshFrontLeft}" >
            <Viewport2DVisual3D.Transform>
                <StaticResource ResourceKey="WorldTranslation" />
            </Viewport2DVisual3D.Transform>
            <StackPanel Background="Blue" Width="80" Height="80">
                <Button Height="30" Margin="20">
                    <Button.Content>Blah</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 个答案:

答案 0 :(得分:1)

首先,使用3D KeyFrame动画代替DoubleAnimation。

使用(Transform3DGroup.Children)而不是

更正您的StoryBoard.TargetProperty的语法

还检查一下: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/78170274-a585-4cd6-85ed-edfd655d34ab