Silverlight Nested Storyboard: Completed Event not Firing for Children

Posted on 2011-04-25
Last Modified: 2012-05-11
I am animating an electrical circuit in Silverlight with nested Storyboards, in which two of the nested storyboards need to trigger a C# routine upon completion (to change a switch).  I am only getting the first Completed event (sbOn_Completed); the sbOff_Completed does not fire, and in the second iteration of sbCycle neither Completed events fire.  If there is not a solution to getting these events, is there a way to trigger a C# routine based on the parent storyboard timer ("at 1.818 seconds into sbCycle execute such-and-such event handler routine")?  

            <!-- sbRun is a wrapper storyboard around the sbCycle sb, which repeats twice, with two nested sbs sbOn and sbOff -->
            <Storyboard x:Name="sbRun" >
                <DoubleAnimation Storyboard.TargetName="ttTimeMark" Storyboard.TargetProperty="X" BeginTime="0:0:0.1" Duration="0:0:20.2" From="0"  To="400" RepeatBehavior="1x"/>
                <Storyboard x:Name="sbCycle" BeginTime="0:0:0" Duration="0:0:10" RepeatBehavior="2x" >
                    <Storyboard x:Name="sbOn"  Completed="sbOn_Completed">
                        <DoubleAnimation Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="Width" From="20" To="40" BeginTime="0:0:0" Duration="0:0:1.818" RepeatBehavior="1x" />
                    <Storyboard x:Name="sbOff" Completed="sbOff_Completed">
                        <DoubleAnimation Storyboard.TargetName="rectangle2" Storyboard.TargetProperty="Width" From="20" To="80"  BeginTime="0:0:1.819" Duration="0:0:8.182" RepeatBehavior="1x" />
Question by:misamexp

    Author Comment

    There has been no feedback on this.  I think Silverlight is fairly new so hopefully the knowledge base for this general area will increase on e-e.  Here is an update:

    1.  I have a mistake: the two child Storyboards (sbOn, sbOff) within the parent Storyboard sbCycle are consecutive, with the second one ending exactly at the same time as the parent [sbCycle=10sec = sbOn(1.818) + sbOff(8.182)].  Caution: Be sure all child storyboards end prior to the parent!
    2. The "Completed" event for children of the second execution of  sbCycle - they do not fire .  It would be nice to be able to nest storyboards and have a Completed event fired at the end of each child.  (It would also be handy to have a "BeforeStart" event.)
    3. In the end I am not using nested storyboards, but just dumping all animations into one long storyboard.  However, this is not cool, as I would like to have a code-behind process execute in the middle of the storyboard based on elapsed time within the storyboard (there may be an easy way to do this but I do not know how).  

    I am leaving this open for now. Any suggestions on synchronizing a storyboard with external C# code-behind processes, or on how to manage nested storyboards, would be most appreciated.  I really do think Silverlight is great, and enjoy working with it.

    Accepted Solution

    In the end I decided to keep the two nested storyboards un-nested and not try to consider the two as subsets of a parent storyboard.  This is worked out ok.  If anyone has ideas as to when nesting storyboards is a good idea and how to syncrhonize the nested objects, it would be of interest.  

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now