![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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) |
| | 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) |
| | 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) |
| | 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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Aero Animation Problems | Vista General | |||
| Merge 2 XML Documents using XSLT Transform | .NET General | |||