Slow Down Refresh Rate of Linked DataGrid

I have a DataGrid in my WPF / C # application that is associated with an Entity Framework collection. Each row has related columns that change very often - many times per second. This causes the column to be mostly unreadable because it changes so often. How to make WPF only show a new value every 0.5 seconds or 1 second, even if the value changes every 0.1 seconds?

eg.

dataGrid.MaxRefreshRate = 1000; (value in milliseconds). 
+3
c # refresh data-binding wpf datagrid
Dec 15 '10 at 10:27
source share
3 answers

I think you need to create a layer between your data and datagrid.

Suppose your data is of type List <Record> and is currently bound to your DataGrid.

We will need some wrapper class for your data (for one row in this case). This shell modifies the property and launches it regularly. Please note: I wrote this code by heart without any testing, there may (and will) be errors. It is also not thread safe, you need to add some locks when working with the list. But the point must be removed.

 public class LazyRecord : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { if (name != value) { name = value; OnPropertyChanged("Name"); } } // other properties // now the important stuff - deffering the update public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (this.changedProperties.Find(propertyName) == null) this.changedProperties.Add(propertyName); } private readonly List<string> changedProperties = new List<string>(); // and the timer that refreshes the data private readonly Timer timer; private readonly Record record; public LazyRecord(Record record) { this.timer = new Timer(1000, OnTimer); this.record = record; this.record.OnPropertyChanged += (o, a) => this.OnPropertyChanged(a.PropertyName); } public void OnTimer(..some unused args...) { if (this.PropertyChanged != null) { foreach(string propNAme in changedProperties) { PropertyChanged(new PropertyChangedEventArgs(propName)); } } } 

After that, just create the <LazyRecord> list from your <Record> list and use this as a data source. Obviously, just using a generic solution that is much more reusable. Hope I helped a bit.

+2
Dec 30 '10 at 3:28
source share

Just an idea of ​​how it can work.

  • Have a shadow copy of the data bound to the gui element, instead of binding the original data.
  • Add an event handler that updates the shadow copy with a certain delay from the source data.

You may find more and better answers to a similar newer question, how-to-do-the-processing-and-keep-gui-refreshed-using-databinding

+1
Dec 25 '10 at 19:07
source share

Try listView.Items.Refresh(); .

-one
Dec 15 '10 at 11:24
source share



All Articles