有一些类似的线程,但我没有找到我的问题的解决方案。这是我在这里发表的第一篇文章 事情就是这样:
Viewport3D viewPort3D;
GeometryModel3D geometryModel = new GeometryModel3D();
Transform3DGroup transform3DGroup = new Transform3DGroup();
...
// Rotation
RotateTransform3D rotateTransform3D = new RotateTransform3D();
AxisAngleRotation3D axisAngleRotation3d = new AxisAngleRotation3D();
axisAngleRotation3d.Axis = new Vector3D(0, 1, 0);
axisAngleRotation3d.Angle = angle;
rotateTransform3D.Rotation = axisAngleRotation3d;
transform3DGroup.Children.Add(rotateTransform3D);
// Translation
TranslateTransform3D translateTransform3D = new TranslateTransform3D();
translateTransform3D.OffsetX = offsetX;
transform3DGroup.Children.Add(translateTransform3D);
// Adding transforms
geometryModel.Transform = transform3DGroup;
Model3DGroup model3DGroup = new Model3DGroup();
model3DGroup.Children.Add( image.getGeometryModel3D() );
modelVisual3D.Content = model3DGroup;
viewPort3D.Children.Add( modelVisual3D );
现在我想使用storyboard进行翻译(因为后来我想添加旋转到那个故事板):
Storyboard s = new Storyboard();
Transform3DGroup transform3DGroup = model3DGroup.Children.ElementAt(current).Transform as Transform3DGroup;
for (int j = 0; j < transform3DGroup.Children.Count; ++j)
{
if (transform3DGroup.Children.ElementAt(j) is TranslateTransform3D)
{
TranslateTransform3D translation = transform3DGroup.Children.ElementAt(j) as TranslateTransform3D;
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 0;
doubleAnimation.To = 2;
doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
doubleAnimation.AutoReverse = true;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
s.Children.Add(doubleAnimation);
s.Duration = new Duration(TimeSpan.FromSeconds(1));
Storyboard.SetTarget(doubleAnimation, model3DGroup.Children.ElementAt(current));
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Model3D.Transform).(Transform3DGroup.Children)[1].(TranslateTransform3D.OffsetX)"));
s.Begin(); // Exception during the execution.
}
}
最后一行中的例外:
路径中的'[未知]'属性值 '(Model3D.Transform)。(Transform3DGroup.Children)[1]。(TranslateTransform3D.OffsetX)' 指向不可变的实例 'System.Windows.Media.Media3D.TranslateTransform3D'。
我将PropertyPath与混合4中生成的路径类似。
感谢您的帮助。
答案 0 :(得分:0)
您的错误表明TranslateTransform3D
是不可变的,意味着什么,它无法更改。并且您正在尝试为其中一个属性设置动画,因此会出错。
答案 1 :(得分:0)
我认为因为translate tranform 3d是一个不可变的实例,所以必须指出它在渲染/翻译过程中应该是可变的。
我想
我们可以将x:Name
提供给该不可变TranslateTransform3D
个对象,以使其可变。
绑定其属性而非动画。
E.g。在你的情况下
NameScope.SetNameScope(this, new NameScope());
this.RegisterName("AxisRotation", MyAxisRotation3DObject.Rotation);
this.RegisterName("TranslateTransformation", MyTranslation3DObject);
这样我们为Axis Rotation 3D和Translate Transform 3D对象命名,然后在双动画中将它们称为Storyboard.SetTargetName(.., "AxisRotation")
和Storyboard.SetTargetName(.., "TranslateTransformation")
并访问它们的直接属性,例如Storyboard.SetTargetProperty(.., new PropertyPath("Angle"))
和{ {1}} resp。