Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Seems that after a bit of Googling I solved the problem myself. Many thanks to <a href="http://msdn.microsoft.com/en-us/library/ms742868.aspx" rel="noreferrer">MSDN documentation</a> and <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/594c9b9b-624b-42d1-99ad-b5084f5f5325" rel="noreferrer">a post in MSDN forums by Antares19</a>.</p> <p>In summary:</p> <ul> <li><p>For a Freezable object (like TranslateTransform) to be targetable by an Storyboard, it must have a registered name. This can be done by calling FrameworkElement.RegisterName(..).</p></li> <li><p>I added the Storyboard object to the ResourceDictionary of the same Framework element to which I registered the TranslateTransform. This can be done by calling ResourceDictionary.Add(..)</p></li> </ul> <p>Here's the updated code, which now animates nicely, and registers/deregisters the added resources:</p> <pre><code>using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace AnimationCompletedTest { public partial class MainWindow : Window { Canvas panel; public MainWindow() { InitializeComponent(); MouseDown += DoDynamicAnimation; Content = panel = new Canvas(); } void DoDynamicAnimation(object sender, MouseButtonEventArgs args) { for (int i = 0; i &lt; 12; ++i) { var e = new Ellipse { Width = 16, Height = 16, Fill = SystemColors.HighlightBrush }; Canvas.SetLeft(e, Mouse.GetPosition(this).X); Canvas.SetTop(e, Mouse.GetPosition(this).Y); var tg = new TransformGroup(); var translation = new TranslateTransform(30, 0); var translationName = "myTranslation" + translation.GetHashCode(); RegisterName(translationName, translation); tg.Children.Add(translation); tg.Children.Add(new RotateTransform(i * 30)); e.RenderTransform = tg; panel.Children.Add(e); var anim = new DoubleAnimation(3, 100, new Duration(new TimeSpan(0, 0, 0, 1, 0))) { EasingFunction = new PowerEase { EasingMode = EasingMode.EaseOut } }; var s = new Storyboard(); Storyboard.SetTargetName(s, translationName); Storyboard.SetTargetProperty(s, new PropertyPath(TranslateTransform.YProperty)); var storyboardName = "s" + s.GetHashCode(); Resources.Add(storyboardName, s); s.Children.Add(anim); s.Completed += (sndr, evtArgs) =&gt; { panel.Children.Remove(e); Resources.Remove(storyboardName); UnregisterName(translationName); }; s.Begin(); } } [STAThread] public static void Main() { var app = new Application(); app.Run(new MainWindow()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload