2010-03-25 44 views
1

我有一个小问题,我搜索谷歌和我的WPF的书,但我不发现我已经创建了一个小故事板的任何答案:(如何以编程方式将故事板应用于标签?

<Storyboard x:Key="whiteAnim" Duration="1"> 
     <ColorAnimation By="Black" To="White" Storyboard.TargetProperty="Background" x:Name="step1"/> 
     <ColorAnimation By="White" To="Black" Storyboard.TargetProperty="Background" x:Name="step2"/> 
</Storyboard> 

该动画将改变背景颜色从黑到白,从白到黑 我想“应用”这个故事板的标签:

Label label = new Label(); 
label.Content = "My label"; 

我正在寻找像“label.StartStoryboard的方法( - myStoryboard- - ),你有什么想法吗?

谢谢:)

回答

2

它应与

public void StartStoryboard() { 
    whiteAnim.Target = label; 
    whiteAnim.Begin(); 
} 

public void StartStoryboard() { 
    Storyboard.SetTarget(whiteAnim, label); 
    whiteAnim.Begin(); 
} 
+0

工作,谢谢你,它工作正常:) – 2010-03-30 09:13:41

相关问题