【问题标题】:WPF PropertyPath Issue - Cannot resolve all property references in property pathWPF PropertyPath 问题 - 无法解析属性路径中的所有属性引用
【发布时间】:2010-12-24 10:16:47
【问题描述】:

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

这是我正在使用的属性路径...

(Viewport2DVisual3D.Transform).(Transform3DGroup)[0].(RotateTransform3D).(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)

编辑:多亏了 Anurags 的建议,我有了更进一步的... (Viewport2DVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)

但现在出现“Rotation property does not point to a 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>

【问题讨论】:

    标签: wpf storyboard


    【解决方案1】:

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

    并使用 (Transform3DGroup.Children) 而不是

    更正 StoryBoard.TargetProperty 的语法

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

    【讨论】:

    • 嗨,谢谢你的帮助,我一定会看看使用 KeyFrames 而不是我的双动画 - 但关于属性路径 - 我尝试按照你的建议添加 .Children,我还删除了第一个 RotateTransform3D,因为我意识到它不是必需的……这就是我现在得到的……(Viewport2DVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)但现在它的“旋转”属性错误并不指向依赖对象。请问您有什么想法吗?
    • 我在使用双动画时也遇到了同样的错误,这就是我说使用 3D 关键帧动画而不是双动画的原因。没时间用 3D 关键帧动画检查它,你试试!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    相关资源
    最近更新 更多