locked
begin animation in the foreground RRS feed

  • Question

  • hi,

    When we implement an animation , what we always do is define a storyboard in xmal , then we start and stop the storyboard in code behind. I wonder that whether we could not only define the storyboard but also we could start animation at the same time?

    any tips will be appricated.

    Wednesday, May 14, 2014 12:53 PM

Answers

  • Hi, you can use EventTrigger ro DataTrgger to start animation, please see below link for more details and example:

    http://msdn.microsoft.com/en-us/library/bb979699(v=vs.95).aspx

    http://msdn.microsoft.com/en-us/library/ff724015(v=expression.40).aspx


    Wednesday, May 14, 2014 2:29 PM
  • Hi,

    As you begin to implement animations in your Silverlight applications, you will find that some of them should be started by the managed code. However, some animations should be started as soon as the application is loaded.

    Starting the animation when the page is loaded is possible by nesting the Storyboard control in an EventTrigger element for the root layout control. The following code shows an example of nesting a Storyboard control in an EventTrigger element of a Grid control:

    <Grid x:Name="LayoutRoot" Background="White">
            <Grid.Triggers>
                <EventTrigger RoutedEvent="Grid.Loaded">
                    <TriggerActionCollection>
                        <BeginStoryboard>
                            <Storyboard AutoReverse="True" RepeatBehavior="Forever">
                                <PointAnimation To="50,350" Storyboard.TargetName="line4" 
                    Storyboard.TargetProperty="EndPoint" />
                            </Storyboard>
                        </BeginStoryboard>
                    </TriggerActionCollection>
                </EventTrigger>
            </Grid.Triggers>
            <Border x:Name="brdTest" BorderBrush="Green" BorderThickness="4" 
            Width="400" Height="400">
                <Path Stroke="Black" StrokeThickness="1">
                <Path.Data>
                    <GeometryGroup>
                        <LineGeometry x:Name="line4" StartPoint="100,150" 
                EndPoint="200,250" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
            </Border>
       </Grid>

    The EventTrigger attaches to the Loaded event to the Grid element and then defines the BeginStoryboard element as part of the TriggerActionCollection.

    Best Regards,
    Qimin Ding


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, May 15, 2014 9:04 AM

All replies

  • Hi, you can use EventTrigger ro DataTrgger to start animation, please see below link for more details and example:

    http://msdn.microsoft.com/en-us/library/bb979699(v=vs.95).aspx

    http://msdn.microsoft.com/en-us/library/ff724015(v=expression.40).aspx


    Wednesday, May 14, 2014 2:29 PM
  • Hi,

    As you begin to implement animations in your Silverlight applications, you will find that some of them should be started by the managed code. However, some animations should be started as soon as the application is loaded.

    Starting the animation when the page is loaded is possible by nesting the Storyboard control in an EventTrigger element for the root layout control. The following code shows an example of nesting a Storyboard control in an EventTrigger element of a Grid control:

    <Grid x:Name="LayoutRoot" Background="White">
            <Grid.Triggers>
                <EventTrigger RoutedEvent="Grid.Loaded">
                    <TriggerActionCollection>
                        <BeginStoryboard>
                            <Storyboard AutoReverse="True" RepeatBehavior="Forever">
                                <PointAnimation To="50,350" Storyboard.TargetName="line4" 
                    Storyboard.TargetProperty="EndPoint" />
                            </Storyboard>
                        </BeginStoryboard>
                    </TriggerActionCollection>
                </EventTrigger>
            </Grid.Triggers>
            <Border x:Name="brdTest" BorderBrush="Green" BorderThickness="4" 
            Width="400" Height="400">
                <Path Stroke="Black" StrokeThickness="1">
                <Path.Data>
                    <GeometryGroup>
                        <LineGeometry x:Name="line4" StartPoint="100,150" 
                EndPoint="200,250" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
            </Border>
       </Grid>

    The EventTrigger attaches to the Loaded event to the Grid element and then defines the BeginStoryboard element as part of the TriggerActionCollection.

    Best Regards,
    Qimin Ding


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, May 15, 2014 9:04 AM