如何将WPF Xaml转换为c#代码?

时间:2015-04-06 10:47:28

标签: c# wpf

我有这个Xaml代码,我想将其转换为c#:

<Storyboard x:Key="sb_hr">
    <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="ellipse">
        <EasingThicknessKeyFrame KeyTime="0" Value="56,48,0,0"/>
        <EasingThicknessKeyFrame KeyTime="0:0:1" Value="400,48,0,0"/>
    </ThicknessAnimationUsingKeyFrames>
</Storyboard>

我该怎么做?

1 个答案:

答案 0 :(得分:1)

请尝试以下代码。

EasingThicknessKeyFrame estf1 = new EasingThicknessKeyFrame();
estf1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1));
estf1.Value = new Thickness(56, 48, 0, 0);
EasingThicknessKeyFrame estf2 = new EasingThicknessKeyFrame();
estf2.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1));
estf2.Value = new Thickness(400, 48, 0, 0);

ThicknessAnimationUsingKeyFrames th = new ThicknessAnimationUsingKeyFrames();
th.SetValue(Storyboard.TargetProperty, FrameworkElement.MarginProperty);
th.SetValue(Storyboard.TargetNameProperty, ellipse);
th.KeyFrames.Add(estf1);
th.KeyFrames.Add(estf2);