Solved

Silverlight 2 Point animation

Posted on 2008-09-30
1
1,387 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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