Solved

Silverlight 2 Point animation

Posted on 2008-09-30
1
1,388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Problem updating Access table using VB code 8 58
Enable Clear Text in Win 8.1 7 47
Having Trouble with MS Access 2010 CommandBars 19 110
Application vs Workbook.applicaiton 3 45
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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