0

My WPF program's storyboard animations stutter ruining user experience (for example on adding larger number of items to ObservableCollection and ListBox being updated).

My idea was to make animation run smoother by dispatching them with higher priority so I tried

Storyboard sb = new Storyboard();
 //all animations
this.Dispatcher.Invoke(()  =>
    { sb.Begin(); 

    }, System.Windows.Threading.DispatcherPriority.Send);

I thought there would be difference between "Send" as highest priority and "SystemIdle" as lowest, but there isn't.

I hope there is small problem in my understanding of the dispatcher and there is a simple fix, but I am open to any ideas of improving animation performance.

EDIT

  1. Implemented on each animated control RenderTargetBitmap which takes screenshot on animation start and replaces complicated visual tree with one image control, and switches it back when animation is complete
  2. Populating listbox that ruins my animation in Dispatcher with SystemIdle priority
  3. Set framerate to 30
  4. Checked in perfmon and nothing seems software rendered, RenderTier is 2

If I disable populating listbox completely everything runs smoothly

Listbox is populated like this

Task.Factory.StartNew(() =>
{
  List<MyData> _f = new List<MyData>();
  //populate _f
  Dispatcher.BeginInvoke(new Action(() => {
    _MyCollection.Clear();
    _MyCollection.AddRange(_f); //Adding items without raising events *
  }), DispatcherPriority.SystemIdle);
}

*I even use addRange for ObservableCollection from ObservableCollection : calling OnCollectionChanged with multiple new items

6
  • There's no easy way to improve performance. Dispatcher priority is about when animation will start, not about what priority animating each frame will have (it's hardcoded I think). If animated items aren't changed and just move, you can try bitmap caching. Besides that, the only way to improve performance is to simplify items. AFAIK.
    – Athari
    Feb 4, 2014 at 23:32
  • try this. Also, make sure everything is being hardware-accelerated. there are tools for that.
    – Fede
    Feb 5, 2014 at 0:44
  • @Athari I had high hopes for bitmap caching, but there was no difference.
    – Daniel
    Feb 5, 2014 at 16:12
  • @HighCore I already had it set to 30. For 300ms quick transition I get only 2 frames in-between.
    – Daniel
    Feb 5, 2014 at 16:14
  • Is there a way to somehow RenderTargetBitmap of the whole grid, do the animations and transitions and then replace bitmap with original control?
    – Daniel
    Feb 5, 2014 at 16:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.