Solved

Silverlight 2 Point animation

Posted on 2008-09-30
1
1,384 Views
Last Modified: 2013-11-12
I'm working with animation in Silverlight 2 and am able to get some stuff working, but I am having problems trying to animate a polygon object's points.  I've got a polygon with four points...

<Polygon x:Name="poly1"
                MouseLeftButtonDown="poly1_MouseLeftButtonDown"
                Points="100,100 200,100 200,200 100,200"
                Stroke="Blue"
                StrokeThickness="2">
                <Polygon.Fill>
                    <SolidColorBrush Color="LightBlue"></SolidColorBrush>
                </Polygon.Fill>
                <Polygon.RenderTransform>
                    <RotateTransform CenterX="150" CenterY="150" Angle="0" />
                </Polygon.RenderTransform>
            </Polygon>

I am trying to alter the 4 points of the polygon so that it changes into a different shape, size, and location.  In the following code, all of the animations work perfectly except for the last one that deals with the points.  I have tried to use PointAnimation instead of DoubleAnimation but it still throws an error when loading the silverlight object.

<Storyboard x:Name="myStoryBoard">
                <DoubleAnimation
                    Storyboard.TargetName="poly1"
                    Storyboard.TargetProperty="Opacity"
                    From="1.0" To="0.0" Duration="0:0:2"
                    AutoReverse="True" RepeatBehavior="Forever" />
                <ColorAnimation
                    Storyboard.TargetName="poly1"
                    Storyboard.TargetProperty="(Polygon.Fill).(SolidColorBrush.Color)"
                    From="LightBlue" To="Red" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
                <DoubleAnimation
                    Storyboard.TargetName="poly1"
                    Storyboard.TargetProperty="(Polygon.RenderTransform).(RotateTransform.Angle)"
                    From="0.0" To="90.0" Duration="0:0:5" AutoReverse="False" RepeatBehavior="Forever" />
                <DoubleAnimation
                    Storyboard.TargetName="poly1"
                    Storyboard.TargetProperty="Points"
                    From="100,100 200,100 200,200 100,200" To="100,300 200,300 300,200 300,200" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />

Any ideas?
0
Comment
Question by:josephdaviskcrm
1 Comment
 
LVL 8

Accepted Solution

by:
adler77 earned 500 total points
ID: 22611670
Animating points is a bit verbose with Silverlight. You do need to use a PointAnimation, but can only animate one point per animation. To do this, you'll probably need to go to a Path, like the snippet below (add your transform, fill, and stroke just like the polygon). You then create a series of PointAnimations, each targetting a point, so you'll need four animations to move the four points. If you are going to be doing a lot of this, you may want to try and get some of this functionality into a user or custom control.
<Path>

    <Path.Data>

        <PathGeometry>

            <PathGeometry.Figures>

                <PathFigure x:Name="Point0" StartPoint="100,100" IsClosed="True" IsFilled="True">

                    <PathFigure.Segments>

                        <LineSegment x:Name="Point1" Point="200,100" />

                        <LineSegment x:Name="Point2" Point="200,200" />

                        <LineSegment x:Name="Point3" Point="100,200" />

                    </PathFigure.Segments>

                </PathFigure>

            </PathGeometry.Figures>

        </PathGeometry>

    </Path.Data>

</Path>

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

14 Experts available now in Live!

Get 1:1 Help Now