0

in my WPF application I have a ListView with a GridView as it's View. The ItemsSource of the ListView is bound to an ItemsCollection in the ViewModel.

This GridView has a lot of columns and the ListView can have a lot of items.

When the windows is loading or the user updates this ListView I show a loading animation while retrieving the new data from the server and updating the ItemsCollection in the ViewModel with the new data.

This retrieving of data is already done asynchronously, so the loading animation keeps spinning. But as soon as the data is retrieved and the binding is to update the ListView, the loading animation freezes until the update of the UI is finished.

How can I make my loading animation keep spinning even when the binding updates the UI?

Thank you for your help.

Nostromo
  • 1,177
  • 10
  • 28
  • Are you updating an ObservableCollection with a number of records? If so, a CollectionChanged event is being fired for each individual record addition. Each event will trigger a UI update. – Eric Olsson Aug 25 '17 at 18:54
  • Yes, I update an ObservableCollection in the ViewModel, and this UI update is freezing the animation that happens on the UI thread as well. – Nostromo Aug 25 '17 at 19:06
  • I had a problem where I needed to add ~1k entries to an ObservableCollection and the UI was becoming unresponsive for seconds. I solved it by creating a class deriving from ObservableCollection that had a BulkAdd() method. It only raised a single event after all the entries were added. Performance improved greatly. – Eric Olsson Aug 25 '17 at 19:28
  • Try [this](https://stackoverflow.com/a/851129/23074) and see if the UI problems go away. – Eric Olsson Aug 25 '17 at 19:32
  • But that won't help in the general problem that updating the UI will freeze anything else on the UI, including animations that show to the user that something is done. – Nostromo Aug 26 '17 at 05:26
  • I hoped that I'm not the only one with this problem and that Microsoft had general cure for that. – Nostromo Aug 26 '17 at 05:27
  • With how many itens the UI freeze? – bruno.almeida Aug 27 '17 at 21:07
  • The animation will not run smooth, when adding items to the ObservableCollection, that is bound to the UI. As soon as I'm done with adding the items, the animation will run smooth again. But what is a "Working..." animation good for if it's not animating while the work is done? – Nostromo Sep 15 '17 at 06:03

1 Answers1

-1

EDIT:

Well, that binding runs in the main thread, the same thread your animation runs.

Clearly my previous solution wont help you. You will have to find a way to reduce the time it takes to rendering view. Share some working code, maybe someone can help you.

Other alternative is to stop the animation and show something static. That way you hide the problem. Its not a great solution, but if you don't find other, this could your only one.

bruno.almeida
  • 2,746
  • 1
  • 24
  • 32
  • I know, I already get my data asynchronously. It's the update of the binding AFTER getting the data that blocks the animation. – Nostromo Aug 25 '17 at 17:43
  • Please share some code. When you say update the binding, is update the binding property that is the source of your ListView? – bruno.almeida Aug 25 '17 at 18:01
  • Yes, I update the ObservableCollection in my ViewModel, the one the ItemsSource of my ListView in bound to. I can only put some code here tomorrow. – Nostromo Aug 25 '17 at 18:36