Reputation: 635
I have a datagrid with 1000 rows. The ItemsSource is a CollectionViewSource. The source for my CollectionViewSource is a BindingList containing objects I've called RowTypes. My RowType object implements INotifyPropertyChanged. One property of every RowType changes about every two seconds. This means that the values in one of the columns of my datagrid change every two seconds.
My problem is that this update effects the user experience. This update takes about a second during which the user cannot do anything with the GUI. If this update happens while the user is scrolling through the records of the datagrid, the scrolling will stop (freeze), and then jump ahead a second later. It's distracting.
Is there a way to keep my window from freezing while updating performing this update?
Upvotes: 0
Views: 2003
Reputation: 7887
Have you tried DeferRefresh()
?
var view = CollectionViewSource.GetDefaultView(RowTypesList);
using (view.DeferRefresh())
{
// perform updates here
}
Upvotes: 0
Reputation: 5935
Just do the read operation in separate thread (not UI thread). WPF will perfectly change scalar property on the view. You can easy start the new task:
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
try
{
// This method is heavy call - to the DataBase or to the WebService
ReadData();
// In this method, do the updates of the properties of
// your RowType collection. You can do it in previous method.
UpdateData();
}
catch (Exception e)
{
// you can log the errors which occurs during data updating
LogError(e);
}
});
Upvotes: 2
Reputation: 15247
Make sure that virtualization is on for your DataGrid. With that on, it should only actually update what is shown on the screen, not all 1000 rows. That shouldn't take a full second unless you've got a crazy number of rows on there I suppose.
Upvotes: 0