0
我有故事板的窗口存儲在窗口的資源,如下所示:如何在窗口加載事件(代碼後面)上觸發StoryBoard?
<Storyboard x:Key="FadeInStoryBoard">
<DoubleAnimation Storyboard.TargetName="GridNotificationWindow" From="0.01" To="1" Storyboard.TargetProperty="Opacity" Duration="0:0:2"/>
<DoubleAnimation Storyboard.TargetName="GridNotificationWindow" From="1" To="0" Storyboard.TargetProperty="Opacity" Duration="0:0:2" BeginTime="0:0:6"/>
</Storyboard>
而且在後面的代碼如下:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Storyboard s = (Storyboard)this.TryFindResource("FadeInStoryBoard");
if(s!=null)
{
BeginStoryboard(s);
}
}
但似乎不工作... 如果我設置它在XAML,它的工作:
<EventTrigger RoutedEvent="Window.Loaded" SourceName="GridNotificationWindow">
<BeginStoryboard x:Name="FadeInStoryBoard" >
<Storyboard>
<DoubleAnimation Storyboard.TargetName="GridNotificationWindow" From="0.01" To="1" Storyboard.TargetProperty="Opacity" Duration="0:0:2"/>
<DoubleAnimation Storyboard.TargetName="GridNotificationWindow" From="1" To="0" Storyboard.TargetProperty="Opacity" Duration="0:0:2" BeginTime="0:0:6"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
如何可以修復後面的代碼?
嘗試's.Begin()'到位BeginStoryboard(S)的',' –
我tryied它,但它不工作:/我也試過s.Begin(本);但仍然不能正常工作.. –
以's.Begin()'結尾處工作正常。 –