Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Problems with Transform Animation

 
 
Old 10-11-2006   #1 (permalink)
John Dunn


 
 

Problems with Transform Animation

I'm attempting to animate a ScaleTransform when dynamically adding a canvas
inside another canvas. The animation works find if begun during the MouseDown
event of the child canvas - it just doesn't run if I attempt to trigger it
right when I add the child to the parent canvas. Is there a way to get this
to work? I want my child canvases to 'zoom' into view when created.

Here's some code that tries to accomplish that. If you click on the main
canvas a blue canvas will be created and it's scale is animated ( but doesn't
work ). Clicking on the new canvas itself will also trigger the animation (
which should work ).

Thanks-

John

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Input;

namespace spiral
{

public class block_t : Canvas
{
public void zoom()
{
ScaleTransform tx = new ScaleTransform();
VisualTransform = tx;
DoubleAnimation anim = new DoubleAnimation();
anim.From = .1;
anim.To = 1;
anim.Duration = new Duration( TimeSpan.FromMilliseconds( 250 ));

tx.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
tx.BeginAnimation(ScaleTransform.ScaleYProperty, anim);
}
public block_t() {
Background = Brushes.Blue;
Width = 200;
Height = 200;
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
zoom();
e.Handled = true;
}

}
public class canvas_t : Canvas
{
public canvas_t()
{
Background = Brushes.AntiqueWhite;
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
Point pt = e.GetPosition( this );
// create a new
block_t b = new block_t();
Children.Add(b);
SetTop(b, pt.Y);
SetLeft(b, pt.X);
b.zoom();
base.OnMouseDown(e);
}
}

public class app_t : Application
{
Window win;
protected override void OnStartup(StartupEventArgs e)
{
win = new Window();
win.Title = "zoom";
win.Content = new canvas_t();
win.Show();
base.OnStartup(e);
}
}

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
app_t app = new app_t();
app.Run();
}
}
}

My System SpecsSystem Spec
Old 10-11-2006   #2 (permalink)
szelee


 
 

Re: Problems with Transform Animation

Hi John,

Just change VisualTransform = tx to RenderTransform = tx in your
zoom() function. That should do the trick.

Cheers,
szelee

On Oct 12, 1:05 am, John Dunn <jhn...@community.nospam> wrote:
> I'm attempting to animate a ScaleTransform when dynamically adding a canvas
> inside another canvas. The animation works find if begun during the MouseDown
> event of the child canvas - it just doesn't run if I attempt to trigger it
> right when I add the child to the parent canvas. Is there a way to get this
> to work? I want my child canvases to 'zoom' into view when created.
>
> Here's some code that tries to accomplish that. If you click on the main
> canvas a blue canvas will be created and it's scale is animated ( but doesn't
> work ). Clicking on the new canvas itself will also trigger the animation (
> which should work ).
>
> Thanks-
>
> John
>
> using System;
> using System.Windows;
> using System.Windows.Controls;
> using System.Windows.Media;
> using System.Windows.Media.Animation;
> using System.Windows.Input;
>
> namespace spiral
> {
>
> public class block_t : Canvas
> {
> public void zoom()
> {
> ScaleTransform tx = new ScaleTransform();
> VisualTransform = tx;
> DoubleAnimation anim = new DoubleAnimation();
> anim.From = .1;
> anim.To = 1;
> anim.Duration = new Duration( TimeSpan.FromMilliseconds( 250 ));
>
> tx.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
> tx.BeginAnimation(ScaleTransform.ScaleYProperty, anim);
> }
> public block_t() {
> Background = Brushes.Blue;
> Width = 200;
> Height = 200;
> }
> protected override void OnMouseDown(MouseButtonEventArgs e)
> {
> zoom();
> e.Handled = true;
> }
>
> }
> public class canvas_t : Canvas
> {
> public canvas_t()
> {
> Background = Brushes.AntiqueWhite;
> }
> protected override void OnMouseDown(MouseButtonEventArgs e)
> {
> Point pt = e.GetPosition( this );
> // create a new
> block_t b = new block_t();
> Children.Add(b);
> SetTop(b, pt.Y);
> SetLeft(b, pt.X);
> b.zoom();
> base.OnMouseDown(e);
> }
> }
>
> public class app_t : Application
> {
> Window win;
> protected override void OnStartup(StartupEventArgs e)
> {
> win = new Window();
> win.Title = "zoom";
> win.Content = new canvas_t();
> win.Show();
> base.OnStartup(e);
> }
> }
>
> static class Program
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main()
> {
> app_t app = new app_t();
> app.Run();
> }
> }
>
> }


My System SpecsSystem Spec
Old 10-12-2006   #3 (permalink)
John Dunn


 
 

Re: Problems with Transform Animation

"szelee" wrote:

> Hi John,
>
> Just change VisualTransform = tx to RenderTransform = tx in your
> zoom() function. That should do the trick.
>
> Cheers,
> szelee


Thanks - that work perfectly. Just curious, how did you happen to know that
would work? I've been faily frustrated with the SDK WinFX documentation so
far - there seems to be quite a bit of trial and error on my part trying to
get things to work properly.

Thanks for your help-

John

My System SpecsSystem Spec
Old 10-12-2006   #4 (permalink)
szelee


 
 

Re: Problems with Transform Animation

You're welcome. While playing with the animation stuff, I came across
this RenderTransform quite often on the documentation and books. In
fact, I do not have much idea what VisualTransform does (the msdn
description doesnt help much either). Hence I copied your code,
replaced that part and it simply works. Glad it helps


John Dunn wrote:
> "szelee" wrote:
>
> > Hi John,
> >
> > Just change VisualTransform = tx to RenderTransform = tx in your
> > zoom() function. That should do the trick.
> >
> > Cheers,
> > szelee

>
> Thanks - that work perfectly. Just curious, how did you happen to know that
> would work? I've been faily frustrated with the SDK WinFX documentation so
> far - there seems to be quite a bit of trial and error on my part trying to
> get things to work properly.
>
> Thanks for your help-
>
> John


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Aero Animation Problems Vista General
Merge 2 XML Documents using XSLT Transform .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46