Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Problems with Transform Animation

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-11-2006   #1 (permalink)
John Dunn
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge 2 XML Documents using XSLT Transform Muhammad Nasir Waqar .NET General 1 07-08-2008 10:30 AM
Transform To Trapezoid Avery Z Avalon 1 06-08-2006 11:14 AM
Camera transform affects hit test results viliescu Avalon 3 01-10-2006 03:54 PM
3D Animation viliescu Avalon 2 01-10-2006 03:53 PM
Cannot animate a transform in a data template viliescu Avalon 6 01-10-2006 03:52 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51