有人可以幫我找出爲什麼這不起作用:動畫在WPF不運行3D
所有的var story = new Storyboard {Duration = TimeSpan.FromSeconds(10)};
var meshBuilder = new MeshBuilder();
meshBuilder.AddCone(new Point3D(0, 0, 0), new Vector3D(0, 0, 1), 15, 10, 50, false, false, 20);
var mesh = meshBuilder.ToMesh();
var geometryModel = new GeometryModel3D
{
Geometry = mesh,
Material = new DiffuseMaterial(new SolidColorBrush(Colors.DeepSkyBlue)),
BackMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.LightBlue)),
};
var modelVisual = new ModelVisual3D { Content = geometryModel };
helixViewport.Children.Add(modelVisual);
var scaleAnimation = new DoubleAnimation
{
BeginTime = TimeSpan.FromSeconds(1),
From = 1,
To = 2,
Duration = new Duration(TimeSpan.FromSeconds(10))
};
var scaleTransform3D = new ScaleTransform3D(1, 1, 2);
var transform3DGroup = new Transform3DGroup();
transform3DGroup.Children.Add(scaleTransform3D);
modelVisual.Transform = transform3DGroup;
story.Children.Add(scaleAnimation);
Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath(ScaleTransform3D.ScaleZProperty));
Storyboard.SetTarget(scaleAnimation, modelVisual);
story.Begin();
首先,我只是用HelixToolkit,在那之後我想擴展它創建一個圓錐體。動畫將持續10秒,並從第1秒和最後10秒開始。但是不執行動畫,縮放後視口僅顯示最終結果。 注意:這是整個代碼的簡化部分,實際代碼將有多個動畫應用於多個模型,每個動畫將在不同的時間開始。這就是爲什麼我想在這裏使用storyboard和BeginTime。請幫我找出我做錯了什麼。
感謝Clemens的幫助,它現在正在工作中:只有2行需要更改:Storyboard.SetTargetProperty(scaleAnimation,new PropertyPath(「Transform.C承運[0] .ScaleZ「));和var scaleTransform3D = new ScaleTransform3D(1,1,1); –