Solved

Silverlight 2 Point animation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

16 Experts available now in Live!

Get 1:1 Help Now