是否有任何工具可以将XAML转换为C#(代码隐藏)?

是否有任何工具可以将XAML转换为C#(代码隐藏)?,c#,wpf,xaml,C#,Wpf,Xaml,我正在寻找一种将一些XAML动画转换为C代码的简单方法。有什么工具可以做这件事吗 谢谢 沃利 这是我试图转换的代码: <Storyboard x:Key="Storyboard1"> <Rotation3DAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="DefaultGroup" Storyboard.TargetProperty="(Visual3D.Trans

我正在寻找一种将一些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>

您可以使用XamlReader.Load(“”)来解析它。希望有帮助:)

编辑:


为什么需要将XAML转换为过程代码?如果我正确地阅读了您的一条注释,那是因为您需要在运行时更改值。如果是这样,可能更好。你能描述一下你想用C做什么,而用XAML做不到吗?

这是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);

感谢您的回答,它可以工作,但我正在尝试在运行时修改一些值,我想我需要直接访问动画中涉及的变量,我将对其进行测试…您应该能够通过children集合访问故事板内容(myStoryBoard.children[0]应该是您的循环)。您也可以尝试完全在codebehind中创建它,请参见:我格式化了您的代码。我希望语法树是对的。请核实。
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);