views:

323

answers:

0

I'm working on a WPF application that displays a number of graphical elements (RectangleGeometries and Splines) that are animated in sync with video displayed in a MediaElement.

The synchronization tree is constructed as follows:

  • Storyboard (for control: Begin(), Pause(), Seek() ...)
    • MediaTimeline (connected to the MediaElement using Storyboard.SetTargetName())
    • ParallelTimeline0 (subdivided in ParallelTimelines to ease object management)
      • KeyframeAnimation0 (animates some graphical element)
      • KeyframeAnimation1 (animates some other graphical element)
      • ...
    • ... (possible more ParallelTimelines...)

Due to the dynamic nature of the elements being displayed and animated, all of this is constructed and managed in code, i.e., no XAML. Setting this up and playing, seeking, etc., works perfectly fine.

The problem I'm facing, however, is the following.

The animated elements can be updated (e.g., Animation KeyFrames are updated, added, removed, ...) from time to time, while the video is still being shown, albeit likely in paused state. Simply updating the original animations has no effect since frozen copies (Freezable) of all animations are apparently used during Storyboard playback (looking at the source code, this freezing seems to occur in the Begin() method when clocks are allocated and animations are applied to Dependency Properties). I've tried making my animations unfreezable (CanFreeze == false), but this just causes exceptions without playing anything.

Is there a way to update only some animations (e.g., only ParallelTimeline0 and children) without forcing the entire Storyboard to be reset and without breaking synchronization with the original MediaTimeline or forcing the MediaTimeline to reload (which involves reloading and re-seeking the associated media and causing significant delay)?