Silverlight Animations Show Line lines

Source: Internet
Author: User
Tags silverlight

Purpose: Displays the line between two points in Silverlight, requiring the animation to display the line effect.

If you need to realize the animation effect you have to understand, Storyborad object:

Storyboard Silverlight

Controls the animation through the timeline and provides object and property target information for its child animations.

Xaml
<storyboard   ...>  oneormorechildtimelines</storyboard>
XAML Value

Value

Describe

Oneormorechildtimelines

Fromone or more of the following object elements derived from Timeline:Storyboard,ColorAnimation,coloranimationusingkeyframes, DoubleAnimation,doubleanimationusingkeyframes,pointanimation, or pointanimationusingkeyframes. When you access the children property at run time, the object element defined here becomes a member of the Children collection.

From the Microsoft Official online definition, we can know that this storyborad is an important element of the implementation of animation.

Notes

You can use the interactive method of the Storyboard object to start the storyboard automatically when the object is loaded or you want to start, pause, resume, and stop the animation.

Storyboard is the only resource type supported by the Resources property.

From the Microsoft Official website we get this thing need to be able to define some eh set under the Canvas.resources node, the official website gives an example of a rectangle color change:

1 <Canvas2   xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml">4   <Rectangle5     x:name= "Myanimatedrectangle"6 Width= "+"7 Height= "+"8 Fill= "Blue">9     <rectangle.triggers>Ten  One       <!--animates the rectangle ' s opacity. - A       <EventTriggerRoutedEvent= "rectangle.loaded"> -         <BeginStoryboard> -           <Storyboard> the             <DoubleAnimation -               Storyboard.TargetName= "Myanimatedrectangle" - Storyboard.TargetProperty= "Opacity" -  from= "1.0" to= "0.0"Duration= "0:0:5"AutoReverse= "True"RepeatBehavior= "Forever" /> +           </Storyboard> -         </BeginStoryboard> +       </EventTrigger> A     </rectangle.triggers> at   </Rectangle> - </Canvas>

Example interpretation:

Under the canvas is a rectangle object that is 100px wide and 100px long, under the Targegers node of rectangle, defines an animation rule that modifies the rectangle transparency (Opacity) property,

Set the transparency to change from 1.0 to 0.0 in 5 seconds, and not repeat, as DoubleAnimation.

With such an example, we know that we want to achieve the line dynamic display effect, it is necessary to use the object has a Storyboard object, and to create a modified X2 under the object, Y2 Way (whether by doubleannimation or coloranimation, or by other means)

We'll set a line to let him initialize the point at 500,500, and when it starts playing, from 500,500 to (200,200):

 Private voidMyButton_Click (Objectsender, RoutedEventArgs e) {Line Myline=NewLine (); Myline.x1= -; Myline.y1= -; Myline.x2= -; Myline.y2= -; Myline.stroke=NewSolidColorBrush (Color.FromArgb (255,255,0,0)); Myline.fill=NewSolidColorBrush (Color.FromArgb (255,255,0,0)); //Add a rectangle to the canvas             This. CNSDESIGNERCONTAINER.CHILDREN.ADD (Myline); //Create two animations of type double and set playback time to 2 secondsDuration Duration =NewDuration (Timespan.fromseconds (2)); DoubleAnimation MyDoubleAnimation1=NewDoubleAnimation (); DoubleAnimation MyDoubleAnimation2=NewDoubleAnimation (); Mydoubleanimation1.duration=duration; Mydoubleanimation2.duration=duration; //Create a story version and add the two double animations aboveStoryboard SB =NewStoryboard (); Sb. Duration=duration; Sb.            Children.add (MyDoubleAnimation1); Sb.            Children.add (MyDoubleAnimation2); //set Target destination value for animationStoryboard.settarget (MyDoubleAnimation1, myline);            Storyboard.settarget (MyDoubleAnimation2, myline); //set the animation's change propertiesStoryboard.settargetproperty (MyDoubleAnimation1,NewPropertyPath ("(X2)")); Storyboard.settargetproperty (MyDoubleAnimation2,NewPropertyPath ("(Y2)")); Mydoubleanimation1.to= $; Mydoubleanimation2.to= $; if(!cnsdesignercontainer.resources.contains ("unique_id"))            {                //Add the animation version to the canvas resource, note: The unique_id must be a unique key not in the resourceCNSDESIGNERCONTAINER.RESOURCES.ADD ("unique_id", SB); Sb.completed+=NewEventHandler (sb_completed); //Playsb.            Begin (); }            Else{SB=NULL;            CnsDesignerContainer.Children.Remove (Myline); }        }        voidSb_completed (Objectsender, EventArgs e) {            //When playback is complete, remove the resource, or you will get an error when you click againCnsDesignerContainer.Resources.Remove ("unique_id"); }

The displayed effect is exactly how the drawing line is animated.

Silverlight Animations Show Line lines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.