title: Animating a MatrixTransform in WPF from code
body: <p>I have a Canvas which I would need to animate the RenderTransform property of.  The start and end matrices will be abitrary, so I can't pre write the storyboard in XAML, so I'm trying to do it in code, I can't find any example of how to do this, below is my best try which does not work (it compiles and runs, but the rendertransform does not change).</p>
  
  <p>Any suggestions on how this should be done?</p>
  
  <pre><code>MatrixAnimationUsingKeyFrames anim = new MatrixAnimationUsingKeyFrames();
  MatrixKeyFrameCollection keyframes = new MatrixKeyFrameCollection();
  DiscreteMatrixKeyFrame start = new DiscreteMatrixKeyFrame(fromMatrix, KeyTime.FromPercent(0));
  DiscreteMatrixKeyFrame end = new DiscreteMatrixKeyFrame(toMatrix, KeyTime.FromPercent(1));
  
  keyframes.Add(start);
  keyframes.Add(end);
  anim.KeyFrames = keyframes;
  
  Storyboard.SetTarget(anim, World.RenderTransform);
  Storyboard.SetTargetProperty(anim, new PropertyPath("Matrix"));
  
  Storyboard sb = new Storyboard();
  sb.Children.Add(anim);
  sb.Duration = TimeSpan.FromSeconds(4);
  sb.Begin();
  </code></pre>