![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |