2015-04-06 150 views
-1

我有我想轉換成C#這XAML代碼:如何將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> 

我怎麼能這樣做?

+0

在代碼中創建故事板很容易。如果你解釋爲什麼你想用C#而不是XAML創建故事板,有人可以增加價值嗎? – sthotakura 2015-04-06 12:14:43

+2

Stackoverflow不是代碼寫入服務。告訴我們你已經嘗試過了。 – 2015-04-06 14:48:02

回答

0

嘗試下面的代碼。

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