I have a window with StoryBoard that stored in Window's resource as follows:
<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> And in code behind as follows:
private void Window_Loaded(object sender, RoutedEventArgs e) { Storyboard s = (Storyboard)this.TryFindResource("FadeInStoryBoard"); if(s!=null) { BeginStoryboard(s); } } But it seems that is not working... If i set it in xaml, it's working:
<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> How to can i fix for code behind?
s.Begin()in place ofBeginStoryboard(s);s.Begin().