我正在寻找一种简单的方法将一些XAML动画转换为C#代码。有没有可用的工具?
谢谢!
沃利
这是我要转换的代码:
<Storyboard x:Key="Storyboard1">
<Rotation3DAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="DefaultGroup"
Storyboard.TargetProperty="(Visual3D.Transform).(Transform3DGroup.Children)[2].(RotateTransform3D.Rotation)">
<SplineRotation3DKeyFrame KeyTime="00:00:04.0200000">
<SplineRotation3DKeyFrame.Value>
<AxisAngleRotation3D Angle="144.99999999999997" Axis="1,0,0"/>
</SplineRotation3DKeyFrame.Value>
</SplineRotation3DKeyFrame>
</Rotation3DAnimationUsingKeyFrames>
</Storyboard>
答案 0 :(得分:2)
您可以使用XamlReader.Load(“”)来解析它。希望它有所帮助:)
编辑:
StoryBoard myStoryBoard = (StoryBoard)XamlReader.Load("code");
答案 1 :(得分:2)
这与c#中的代码相同:
Storyboard storyboard3 = new Storyboard();
storyboard3.AutoReverse = false;
Rotation3DAnimationUsingKeyFrames r3d = new Rotation3DAnimationUsingKeyFrames();
r3d.BeginTime = new TimeSpan(0, 0, 0, 0, 0);
r3d.Duration = new TimeSpan(0,0,0,1,0);
r3d.KeyFrames.Add(new SplineRotation3DKeyFrame(new AxisAngleRotation3D(new Vector3D(1,0,0),1)));
r3d.KeyFrames.Add(new SplineRotation3DKeyFrame(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 37)));
r3d.Name = "r3d";
Storyboard.SetTargetName(r3d, "DefaultGroup");
Storyboard.SetTargetProperty(r3d, new PropertyPath("(Visual3D.Transform).(Transform3DGroup.Children)[2].(RotateTransform3D.Rotation)"));
storyboard3.Children.Add(r3d);
this.BeginStoryboard(storyboard3);
答案 2 :(得分:1)
为什么需要将XAML转换为程序代码?如果我正确阅读了您的一条评论,那是因为您需要在运行时更改值。如果是这种情况,data binding可能会更好。你能描述一下你用XAML无法做的C#吗?