Animating items when added to custom panel
Last post 05-13-2008 10:43 AM by lewisb. 3 replies.
Sort Posts:
05-05-2008 5:59 AM
Animating items when added to custom panel

Hi,

I have created a custom panel which handles the layout of items added to it.

My question is: is it possible to add animations to the panel - so when items (UIElements) are added to the panel they are animated to their new position within the panel ?

 I tried building the animation directly in code:

xaml += "<Storyboard xmlns=\"http://schemas.microsoft.com/client/2007\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" x:Name=\"" + (child as FrameworkElement).Name + "\" Storyboard.TargetName=\"" + (child as FrameworkElement).Name + "\" > ";

xaml += " <DoubleAnimation Storyboard.TargetProperty=\"(Canvas.Left)\" To=\"" + point.X + "\" Duration=\"0:0:0.25\" />";

xaml += " <DoubleAnimation Storyboard.TargetProperty=\"(Canvas.Top)\" To=\"" + point.Y + "\" Duration=\"0:0:0.25\" />";

xaml += "</Storyboard>";

Storyboard storyboard = (Storyboard)XamlReader.Load(xaml);

storyboard.Completed += new EventHandler(storyboard_Completed); (remove when complete)

this.Resources.Add(storyboard);

 storyboard.Begin();

and running it for each item in the "Arrange" pass - but it did not work.

 

Thanks,

s_svane

s_svane

Loading...
Joined on 10-25-2007
Posts 7
05-06-2008 10:32 PM
Re: Animating items when added to custom panel

Hi:

  Are these elements added to a Canvas? If so I think it should work.

Regards

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Loading...
Joined on 03-16-2007
Posts 1,616
05-13-2008 1:45 AM
Re: Animating items when added to custom panel

Hi,

sorry my mistake - the elements are not added to a Canvas as stated in the storyboard. What I am trying to do is to be able to play some kind of animation (move the element to its new position= when i add new elements to my custom panel (which is not based on a canvas).

Regards

s_svane

Loading...
Joined on 10-25-2007
Posts 7
05-13-2008 10:43 AM
Re: Animating items when added to custom panel

Hello,

 I do something similiar in a graphing control I've made.  The solution I came up with it to create an animation for each object.  Although, you may be able to just retarget the animation and set the to/from values to whatever you'd like.

I've created a graphics helper class that handles building the animations for each object.  This creates the animation through code, not building the xaml, but in managed code, here is a small example: 

private static void BuildRisingPathAnim(double start, double offset, LineSegment segment, PointAnimationUsingKeyFrames anim)

{

SplinePointKeyFrame key = new SplinePointKeyFrame();key.SetValue(SplinePointKeyFrame.KeyTimeProperty, TimeSpan.FromSeconds(0));

key.Value = new Point(segment.Point.X, start);

key.KeySpline = new KeySpline();

key.KeySpline.ControlPoint1 = new Point(0.5, 0.0);key.KeySpline.ControlPoint2 = new Point(0.5, 1.0);

anim.KeyFrames.Add(key);

}

 Implementation:

PointAnimationUsingKeyFrames StartUAnim = new PointAnimationUsingKeyFrames();

StartUAnim.BeginTime = TimeSpan.FromSeconds(0);

Storyboard.SetTargetProperty(StartUAnim, "(Path.Data).(PathGeometry.Figures)[0].(PathFigure.StartPoint)");

BuildRisingPathAnim( val1, val2, (LineSegment)this.LineSegments[0], StartUAnim);

 

Here, I'm animating a path, with each segment starting it's animation just a bit behind the previous one.

Hope this helps even a little bit.

-Lewis

lewisb

Loading...
Joined on 01-29-2008
Indiana
Posts 81
Page view counter