I am using an Infragistics XamDataGrid for my grid. It is bound to an ObservableCollection.

When a selection is made in a dropdown in the window, a request for data is made on a background thread and the loading animation is started. As the data is received, the necessary work is done, all on the background thread.

The issue I am facing is that once all of the data is ready, I need to update the collection that the grid is bound to. This needs to be done on the UI thread. So what happens is that while the XamDataGrid is doing its work on the UI thread to deal with the collection change, my animation stops animating.

As far as I can tell, there isn't much I can do since both the grid loading and animation need to occur on the same UI thread.

Is there anything I might have missed? Some way to keep the animation running while the grid is working to display the new rows?

有帮助吗?

解决方案

The first thing I would do is figure out where the performance cost is. Simplify your UI and use WPFPerf to try and figure this out. You may find that you have a particularly expensive data template in your grid, for example.

If you still have performance problems, you can batch your updates into small groups, running each in their own dispatcher message. Pseudo-code:

// running on BG thread
var data = server.GetTheData();

// have the data, so marshal back to the UI thread in batches of 5
foreach (var batch in data.Batch(5))
{
    dispatcher.Invoke(..., batch);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top