0

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?

3
  • 1
    Try s.Begin() in place of BeginStoryboard(s); Commented Mar 19, 2014 at 10:02
  • i tryied it, but it's not working:/ i tried also s.Begin(this); but still not working.. Commented Mar 19, 2014 at 10:14
  • 1
    Works fine at my end with s.Begin(). Commented Mar 19, 2014 at 11:19

1 Answer 1

2

set the target before calling BeginStoryboard

 Storyboard.SetTarget(s, TargetName); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.