【发布时间】:2014-09-04 21:35:47
【问题描述】:
在我的Application.Resources 中,我定义了以下Storyboard。
<Application.Resources>
<!--Storyboard animation for fading out a UI element-->
<Storyboard x:Key="FadeOutAnimation">
<DoubleAnimation From="1"
To="0"
Duration="0:0:0.25"
Storyboard.TargetProperty="Opacity"
AutoReverse="False" />
</Storyboard>
</Application.Resources>
在代码隐藏中,当用户点击它们时,我使用它来淡出一些 TextBlocks。
// Get the storyboard from application resources
Storyboard sb = (Storyboard)App.Current.Resources["FadeOutAnimation"];
// Setup the animation target for fade out
Storyboard.SetTarget( sb.Children.ElementAt( 0 ) as DoubleAnimation, myTextBlock );
// Set the animation completed handler
sb.Completed += ( s, e1 ) => {
// Stop the Storyboard
sb.Stop();
// Hide the TextBlock
myTextBlock.Visibility = Visibility.Collapsed;
};
// Start the Storyboard
sb.begin();
问题是,我是否需要以某种方式“解除”myTextBlock 成为DoubleAnimation 的目标?
如果是,我该怎么做?
我问的原因是我担心在再次使用此 Storyboard 之前会一直引用 TextBlock。
感谢您的帮助!
【问题讨论】:
标签: wpf silverlight windows-phone-7